Skip to content

Commit 5bd946b

Browse files
committed
fixup! feat(@angular/build): add CSP nonce to stylesheet and modulepreload link elements
1 parent d19c014 commit 5bd946b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

  • packages/angular/build/src/utils/index-file

‎packages/angular/build/src/utils/index-file/nonce.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { htmlRewritingStream } from './html-rewriting-stream';
1414
*/
1515
const NONCE_ATTR_PATTERN = /ngCspNonce/i;
1616

17+
const TARGET_LINK_RELS: ReadonlySet<string> = new Set(['stylesheet', 'modulepreload']);
18+
1719
/**
1820
* Finds the `ngCspNonce` value and copies it to all inline `<style>` and `<script> `tags.
1921
* @param html Markup that should be processed.
@@ -41,8 +43,8 @@ export async function addNonce(html: string): Promise<string> {
4143
}
4244

4345
if (tagName === 'link' && attr.name === 'rel' && attr.value) {
44-
const tokens = attr.value.trim().split(/\s+/);
45-
if (tokens.includes('stylesheet') || tokens.includes('modulepreload')) {
46+
const tokens = attr.value.toLowerCase().trim().split(/\s+/);
47+
if (tokens.some((token) => TARGET_LINK_RELS.has(token))) {
4648
isTarget = true;
4749
}
4850
}

0 commit comments

Comments
 (0)