fix(showcase-csp): allow api.github.com so /stats charts populate#52
Merged
Conversation
added 4 commits
May 14, 2026 19:37
…rom api.github.com
8 tasks
Collaborator
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This was referenced May 15, 2026
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.
Why
The /stats Easter-egg page (
showcase/angular/src/app/pages/stats/) was added in quick task 260514-1nv with a client-sideGitHubStatsServicethat fetches 7 endpoints underhttps://api.github.com/repos/LakshmanTurlapati/FSB/*directly from the browser. The page polls every 5 minutes and renders Chart.js views for cumulative stars, weekly stars, issues, forks, PRs, commits-per-week, and maintenance (releases-per-month).The page was dark in production. Every chart card was either showing the "Could not load stats" error or the loading skeleton, even though the repo has 66 stars, 17 releases, 4 forks, 50 issues, 47 PRs, and 2300+ commits.
Root cause: the showcase server's CSP header had
connect-src 'self', so the browser silently blocked everyfetch()toapi.github.com. Confirmed via:GitHub's anonymous public-read endpoints return
Access-Control-Allow-Origin: *, so once CSP allows the host the browser fetches succeed end-to-end with no server-side proxy needed:What
Three files, ~120 lines of net diff (most of it is the new regression test).
1.
showcase/server/server.js— CSP directiveBefore:
After:
Plus an 8-line explanatory comment block above the
SHOWCASE_CSParray naming the consumer so a future tightening doesn't regress this silently:2.
tests/showcase-csp-allows-github-api.test.js— new regression testNode-only, no Express boot — text-parses
showcase/server/server.js, locates theconnect-srcentry in theSHOWCASE_CSParray, and asserts six invariants:showcase/server/server.jsexists and is readableSHOWCASE_CSParray literal is presentconnect-srcdirective is presentconnect-srccontains'self'connect-srccontainshttps://api.github.comconnect-srcdoes not permit bare*ordata:(defense-in-depth)Standalone runnable:
node tests/showcase-csp-allows-github-api.test.js→ exits 0 on pass, 1 with diagnostic on fail.3.
package.json— wire into npm testSingle-token insertion of
&& node tests/showcase-csp-allows-github-api.test.jsintoscripts.testimmediately after the existingshowcase-build-smoke.test.jsinvocation, mirroring that pattern.What I did NOT change
MAX_PAGES = 2ingithub-stats.service.ts— verified all 7 endpoints fit comfortably (only commits exceeds 200, but the only chart that consumes commits is a last-12-weeks window which 200 newest commits more than cover; GitHub returns commits newest-first by default)./api/github-stats/*proxy — the user-facing problem is solved without one, and adding it would be a separate phase (rate-limit headroom + ETag caching is a non-blocking nice-to-have).ROUTE_PATHSall remain free of /stats artifacts (confirmed by the unchangedshowcase-build-smoke.test.jsEaster-egg invariant — still 134/134 passing).Test plan
node tests/showcase-csp-allows-github-api.test.js→ 6 passed, 0 failed)npm testchain green (exit 0)showcase-build-smoke.test.jsstill 130+ assertions passing (/stats Easter-egg invariant intact)new Function(fs.readFileSync('showcase/server/server.js'))parses (no syntax regressions)curl -D - https://full-selfbrowsing.com/stats -o /dev/nullshowsconnect-src 'self' https://api.github.com→ load/statsin browser → Cumulative-stars chart renders all 66 stars from 2025-08-04 onward; commits / forks / issues / PRs / maintenance views populate within the first 5-minute poll.Quick task
Tracked at
.planning/quick/260514-r6i-fix-csp-on-showcase-server-to-unblock-st/(PLAN.md + SUMMARY.md).