-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular/build): add CSP
nonce
attribute to script tags when in…
…line critical CSS is disabled Prior to this change when inline critical CSS is disabled CSP `nonce` was not added to script tags. Closes #28102 (cherry picked from commit 636cb69)
- Loading branch information
1 parent
c0933f2
commit a28615d
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
packages/angular/build/src/builders/application/tests/behavior/csp-nonce_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import { buildApplication } from '../../index'; | ||
import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setup'; | ||
|
||
describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => { | ||
describe('Behavior: "CSP Nonce"', () => { | ||
it('should add CSP nonce to scripts when optimization is disabled', async () => { | ||
await harness.modifyFile('src/index.html', (content) => | ||
content.replace(/<app-root/g, '<app-root ngCspNonce="{% nonce %}" '), | ||
); | ||
|
||
harness.useTarget('build', { | ||
...BASE_OPTIONS, | ||
polyfills: [], | ||
optimization: false, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
|
||
const indexFileContent = harness.expectFile('dist/browser/index.html').content; | ||
indexFileContent.toContain( | ||
'<script src="main.js" type="module" nonce="{% nonce %}"></script>', | ||
); | ||
indexFileContent.toContain('<app-root ngcspnonce="{% nonce %}"'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters