Repository navigation
fix: harden security — meta CSP, security.txt, Firebase WS transport - #146
Merged
Merged
Conversation
therealsama
force-pushed
the
feat/security-csp
branch
2 times, most recently
from
June 14, 2026 08:35
594d86c to
9ecf816
Compare
therealsama
force-pushed
the
feat/security-csp
branch
4 times, most recently
from
June 21, 2026 06:46
100b9c3 to
f6fd162
Compare
therealsama
force-pushed
the
feat/security-csp
branch
from
June 21, 2026 19:08
f6fd162 to
74d7aa7
Compare
therealsama
enabled auto-merge
June 21, 2026 19:19
kplachkov
approved these changes
Jun 21, 2026
auto-merge was automatically disabled
June 21, 2026 19:29
Repository rule violations found
therealsama
enabled auto-merge
June 21, 2026 19:34
therealsama
force-pushed
the
feat/security-csp
branch
2 times, most recently
from
June 22, 2026 07:00
71e0289 to
8a9fa59
Compare
GitHub Pages can't set response headers, so this is done at the static layer: - vite.config.js: build-time <meta http-equiv> Content-Security-Policy. script-src avoids 'unsafe-inline' by hashing every executable inline script post-transform (inert application/ld+json blocks are skipped — script-src doesn't govern them); connect-src allows Algolia + Firebase (incl. wss://, via the *.firebaseio.com wildcard required by RTDB's dynamic shard hosts). Throws if the <meta charset> anchor is missing. Intentionally no upgrade-insecure-requests (it breaks the WebKit preview e2e and buys nothing on HTTPS-only Pages). - vite.config.js: after injecting the CSP, re-parse the final HTML with jsdom (an independent parser, not the extraction regex) and fail the build if any executable inline script lacks a matching hash — closes the regex's " src=" blind spot and guards against future plugins injecting unhashed scripts. - vite.config.js: emit /.well-known/security.txt (RFC 9116) with a build-time Expires (+6 months) so it can't silently go stale. - src/api/hnSdk.ts: pin Firebase RTDB to WebSockets. Its long-poll fallback is JSONP <script> injection to *.firebaseio.com/.lp, which the strict script-src blocks; forceWebSockets() drops that already-dead transport (lossless under CSP). - e2e/csp.spec.ts: assert the production build ships exactly one enforced meta CSP and raises zero violations on load + Firebase-backed navigation. A missing CSP or a dropped inline-script hash is otherwise functionally invisible to the suite. - SECURITY.md: document the policy and the accepted GitHub Pages constraints, including the no-frame-ancestors/no-X-Frame-Options clickjacking gap.
therealsama
force-pushed
the
feat/security-csp
branch
from
June 23, 2026 05:41
8a9fa59 to
ff17b4c
Compare
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.
GitHub Pages can't set response headers, so this is done at the static layer:
<meta http-equiv>Content-Security-Policy. script-srcavoids 'unsafe-inline' by hashing every executable inline script post-transform
(inert application/ld+json blocks are skipped — script-src doesn't govern them);
connect-src allows Algolia + Firebase (incl. wss://, via the *.firebaseio.com
wildcard required by RTDB's dynamic shard hosts). Throws if the
<meta charset>anchor is missing. Intentionally no upgrade-insecure-requests (it breaks the
WebKit preview e2e and buys nothing on HTTPS-only Pages).
independent parser, not the extraction regex) and fail the build if any
executable inline script lacks a matching hash — closes the regex's " src="
blind spot and guards against future plugins injecting unhashed scripts.
Expires (+6 months) so it can't silently go stale.
JSONP
<script>injection to *.firebaseio.com/.lp, which the strict script-srcblocks; forceWebSockets() drops that already-dead transport (lossless under CSP).
and raises zero violations on load + Firebase-backed navigation. A missing CSP or
a dropped inline-script hash is otherwise functionally invisible to the suite.
including the no-frame-ancestors/no-X-Frame-Options clickjacking gap.