-
Notifications
You must be signed in to change notification settings - Fork 686
OCPBUGS-74140: Prevent Chinese characters from rendering as unicode escape sequences in alert messages #16156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,6 +146,18 @@ export const shouldLogout = (url: string): boolean => { | |
| return false; | ||
| }; | ||
|
|
||
| /** | ||
| * Converts Go-style Unicode escape sequences (\uXXXX, \UXXXXXXXX) in K8s API error | ||
| * messages back to actual Unicode characters for proper display in the browser. | ||
| */ | ||
| export const unescapeGoUnicode = (str: string): string => | ||
| str | ||
| .replace(/\\U([0-9a-fA-F]{8})/g, (match, hex) => { | ||
| const codePoint = parseInt(hex, 16); | ||
| return codePoint <= 0x10ffff ? String.fromCodePoint(codePoint) : match; | ||
| }) | ||
| .replace(/\\u([0-9a-fA-F]{4})/g, (_, hex) => String.fromCodePoint(parseInt(hex, 16))); | ||
|
|
||
| export const validateStatus = async ( | ||
| response: Response, | ||
| url: string, | ||
|
|
@@ -183,7 +195,7 @@ export const validateStatus = async ( | |
| if (response.status === 403) { | ||
| return response.json().then((json) => { | ||
| throw new HttpError( | ||
| json.message || 'Access denied due to cluster policy.', | ||
| unescapeGoUnicode(json.message || 'Access denied due to cluster policy.'), | ||
| response.status, | ||
| response, | ||
| json, | ||
|
|
@@ -217,6 +229,6 @@ export const validateStatus = async ( | |
| reason = response.statusText; | ||
| } | ||
|
|
||
| throw new HttpError(reason, response.status, response, json); | ||
| throw new HttpError(unescapeGoUnicode(reason), response.status, response, json); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apply unescape consistently in the 403 JSON error path as well. Right now unescaping is only applied in this branch; the 403 branch still uses raw 💡 Proposed fix if (response.status === 403) {
return response.json().then((json) => {
throw new HttpError(
- json.message || 'Access denied due to cluster policy.',
+ unescapeGoUnicode(json.message || 'Access denied due to cluster policy.'),
response.status,
response,
json,
);
});
}🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fix was applied here but not to the existing 403 handler above (line 194). Could Unicode escapes also appear in 403 json.message responses? If so, should we apply the same treatment there for consistency? |
||
| }); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a test case for invalid/out-of-range escape sequences to ensure the function doesn't throw unexpectedly?