feat: CSP/security headers plugin and critical dependency audit gate - #293
Open
Arome8240 wants to merge 1 commit into
Open
feat: CSP/security headers plugin and critical dependency audit gate#293Arome8240 wants to merge 1 commit into
Arome8240 wants to merge 1 commit into
Conversation
- Add vite-plugin-security-headers.js with Content-Security-Policy, X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy, COOP, CORP, and HSTS headers injected via Vite dev and preview server middleware - Register the plugin in vite.config.js - Add npm audit --audit-level=critical step to CI (runs before tests) - Add 'audit' script to package.json - Add test/security/csp-headers.test.js (25 tests) covering directive correctness, unsafe-inline/eval absence in script-src, and regression guard for missing CSP (original failure mode) - Add test/security/dependency-audit.test.js (8 tests) verifying the audit step and plugin are wired up in CI and vite.config - Update test script to include test/security folder Wallet/provider exceptions: Freighter and Albedo communicate via window.postMessage (browser-extension bridge), not fetch, so no connect-src exemption is required. Stellar Horizon testnet and mainnet are both allowed in connect-src for the Stellar SDK.
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.
Summary
Adds a restrictive Content-Security-Policy and a full set of companion security headers, delivered as a zero-dependency Vite plugin. Also gates the CI pipeline on
npm audit --audit-level=criticalso supply-chain vulnerabilities block builds before tests run.Changes
vite-plugin-security-headers.js— new Vite pluginbuildCsp()andSECURITY_HEADERSfor test assertions and deploy-config generators (nginx, Cloudflare Workers, etc.)default-src 'self',script-src 'self',connect-src 'self' https://horizon-testnet.stellar.org https://horizon.stellar.org,object-src 'none',frame-ancestors 'none',base-uri 'self',form-action 'self',upgrade-insecure-requestsvite.config.js— registers the plugin.github/workflows/ci.yml— addsnpm audit --audit-level=criticalbefore the test steppackage.json— addsauditscript; extendstestscript to includetest/securitytest/security/csp-headers.test.js— 25 unit tests covering every CSP directive, companion headers, and a regression guard for the original failure mode (no CSP present)test/security/dependency-audit.test.js— 8 tests verifying the audit step and plugin registration are wired up in CI and vite.configDesign tradeoffs
style-src 'unsafe-inline'retained<style>tag at build time; removing it breaks rendering. Script execution is unaffected.window.postMessage(browser-extension bridge), not fetch/XHR, so noconnect-srcorscript-srcentry is needed.connect-srcVITE_STELLAR_NETWORK=testnetand=publicwithout requiring a build-time branch.frame-ancestorsorsandbox.--audit-level=criticalonlyTest evidence
npm run build— clean with no errorsfixes #285