Skip to content

Harden preview script CSP#409

Open
yusufm wants to merge 1 commit into
schuyler:mainfrom
yusufm:Codex/fix-preview-csp-019def52-b3da-7962-96cd-afa05d8d1592
Open

Harden preview script CSP#409
yusufm wants to merge 1 commit into
schuyler:mainfrom
yusufm:Codex/fix-preview-csp-019def52-b3da-7962-96cd-afa05d8d1592

Conversation

@yusufm

@yusufm yusufm commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add per-render nonces to renderer-owned preview script tags
  • remove broad file/self script sources and outbound connect permission from the preview CSP
  • add regression coverage for nonce-bearing app scripts and document-supplied file scripts

Validation

  • bundle exec pod install
  • xcodebuild test -workspace "MacDown 3000.xcworkspace" -scheme MacDown -only-testing:MacDownTests/MPAssetTests -only-testing:MacDownTests/MPRendererEdgeCaseTests/testPreviewRenderIncludesContentSecurityPolicyAndCheckboxToken -only-testing:MacDownTests/MPRendererEdgeCaseTests/testPreviewCSPBlocksDocumentSuppliedFileScripts -destination 'platform=macOS'

Related to security review finding: Preview CSP allows local script execution.

@yusufm yusufm marked this pull request as ready for review May 3, 2026 19:56

@schuyler schuyler left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the PR, @yusufm!

Issues

  • MathJax/preview network access: Tightening connect-src from http: https: to 'none' blocks all XHR/fetch from the preview, so it's worth confirming MathJax rendering and the other bundled preview libraries still work, since the prior policy granted that access explicitly.

Suggestions

  • Nonce robustness: The nonce is injected into the script attribute without escaping — safe today since it's an NSUUID hex string, but a small assertion or escape would keep it sound if the generator ever changes.
  • Pin the nonce contract in tests: A test asserting the CSP nonce-… value equals the nonce on the emitted renderer scripts (and that it differs across renders) would lock in the core security property.
  • Changelog: A ### Security entry under [Unreleased] would record that document-supplied file:// preview scripts are now blocked.

Generated by Claude Code

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.

2 participants