Skip to content

Conversation

zhukaihan
Copy link
Collaborator

Summary

Add nonce to new script tags for CSP.

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: no

@zhukaihan zhukaihan requested review from tyiuhc, Copilot and bgiori May 8, 2025 18:18
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a nonce to dynamically loaded script tags to improve Content Security Policy (CSP) compliance.

  • Adds logic in asyncLoadScript to extract and apply a nonce from an existing element in the DOM.
  • Updates the messenger.ts file to include nonce handling for scripts.

Comment on lines +56 to +62
scriptElement.setAttribute(
'nonce',
nonceElem['nonce'] ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(nonceElem as any).nonce ||
nonceElem.getAttribute('nonce'),
);
Copy link
Preview

Copilot AI May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider extracting nonce retrieval into a single variable (e.g., const nonce = nonceElem.getAttribute('nonce') || (nonceElem as any).nonce;) to reduce repetition and improve clarity in the nonce assignment process.

Suggested change
scriptElement.setAttribute(
'nonce',
nonceElem['nonce'] ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(nonceElem as any).nonce ||
nonceElem.getAttribute('nonce'),
);
const nonce =
nonceElem['nonce'] ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(nonceElem as any).nonce ||
nonceElem.getAttribute('nonce');
scriptElement.setAttribute('nonce', nonce);

Copilot uses AI. Check for mistakes.

Copy link

promptless bot commented May 8, 2025

✅ No documentation updates required.

@zhukaihan zhukaihan merged commit 53cd69e into main May 13, 2025
6 checks passed
@zhukaihan zhukaihan deleted the fix-nonce branch May 13, 2025 18:02
ansonchen2 pushed a commit that referenced this pull request Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants