Skip to content

Commit 87a90af

Browse files
committed
fix(@angular/build): incomplete string escaping or encoding
See: https://github.com/angular/angular-cli/security/code-scanning/76
1 parent 0a4ef30 commit 87a90af

File tree

1 file changed

+4
-16
lines changed
  • packages/angular/build/src/utils/server-rendering

1 file changed

+4
-16
lines changed

packages/angular/build/src/utils/server-rendering/manifest.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,8 @@ const MAIN_SERVER_OUTPUT_FILENAME = 'main.server.mjs';
2424
* A mapping of unsafe characters to their escaped Unicode equivalents.
2525
*/
2626
const UNSAFE_CHAR_MAP: Record<string, string> = {
27-
'<': '\\u003C',
28-
'>': '\\u003E',
29-
'/': '\\u002F',
30-
'\\': '\\\\',
31-
'\b': '\\b',
32-
'\f': '\\f',
33-
'\n': '\\n',
34-
'\r': '\\r',
35-
'\t': '\\t',
36-
'\0': '\\0',
37-
'\u2028': '\\u2028',
38-
'\u2029': '\\u2029',
27+
'`': '\\`',
28+
'$': '\\$',
3929
};
4030

4131
/**
@@ -46,7 +36,7 @@ const UNSAFE_CHAR_MAP: Record<string, string> = {
4636
* @returns The escaped string where unsafe characters are replaced.
4737
*/
4838
function escapeUnsafeChars(str: string): string {
49-
return str.replace(/[<>\b\f\n\r\t\0\u2028\u2029]/g, (c) => UNSAFE_CHAR_MAP[c]);
39+
return str.replace(/[$`]/g, (c) => UNSAFE_CHAR_MAP[c]);
5040
}
5141

5242
/**
@@ -149,9 +139,7 @@ export function generateAngularServerAppManifest(
149139
file.path === INDEX_HTML_CSR ||
150140
(inlineCriticalCss && file.path.endsWith('.css'))
151141
) {
152-
serverAssetsContent.push(
153-
`['${file.path}', async () => ${escapeUnsafeChars(JSON.stringify(file.text))}]`,
154-
);
142+
serverAssetsContent.push(`['${file.path}', async () => \`${escapeUnsafeChars(file.text)}\`]`);
155143
}
156144
}
157145

0 commit comments

Comments
 (0)