fix(common/http): add CSP nonce support to JsonpClientBackend#67923
Open
YooLCD wants to merge 1 commit intoangular:mainfrom
Open
fix(common/http): add CSP nonce support to JsonpClientBackend#67923YooLCD wants to merge 1 commit intoangular:mainfrom
YooLCD wants to merge 1 commit intoangular:mainfrom
Conversation
Member
|
Tests are failing. Can you PTAL. |
Author
|
Fixed the constructor issue (removed default |
SkyZeroZx
reviewed
Mar 29, 2026
packages/common/http/src/jsonp.ts
Outdated
| constructor( | ||
| private callbackMap: JsonpCallbackContext, | ||
| @Inject(DOCUMENT) private document: any, | ||
| @Optional() @Inject(CSP_NONCE) private readonly nonce: string | null, |
Contributor
There was a problem hiding this comment.
Possibly for CSP_NONCE we could use
private readonly nonce = inject(CSP_NONCE , { optional: true });Or would there be some reason not to use it?
Author
There was a problem hiding this comment.
Thanks for the suggestion! Updated to use inject(CSP_NONCE, { optional: true }) as a class field.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
JsonpClientBackenddoes not set thenonceattribute on dynamically injected<script>tags. This causes JSONP requests to be blocked in applications that use Content Security Policy withstrict-dynamic, since the browser requires a valid nonce on all dynamically created scripts.All other places in Angular that create
<script>or<style>elements already support CSP nonces via theCSP_NONCEinjection token (e.g.SharedStylesHost,DomRendererFactory2,TransferState).JsonpClientBackendwas the only exception.Issue Number: N/A
What is the new behavior?
JsonpClientBackendnow optionally injects theCSP_NONCEtoken and sets it as thenonceattribute on the created<script>element. The token is injected with@Optional(), so existing applications that do not provideCSP_NONCEare unaffected.Does this PR introduce a breaking change?
Other information
MockScriptElementinjsonp_mock.tshas been updated to supportsetAttribute/getAttributeto enable nonce-related testing.