Skip to content

fix(#54): gate Swagger UI behind non-production, pin version, add SRI - #147

Merged
Busiii-adetiba merged 1 commit into
SynapsVault:mainfrom
euniceamoni:fix/54-swagger-ui-sri-production-gate
Oct 20, 2026
Merged

Busiii-adetiba merged 1 commit into
SynapsVault:mainfrom
euniceamoni:fix/54-swagger-ui-sri-production-gate

Conversation

@euniceamoni

@euniceamoni euniceamoni commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #54.

Changes

src/routes/docs.ts

  • GET /docs is now only registered when NODE_ENV !== 'production'. /openapi.json and /docs/json remain available in all environments.
  • Pinned swagger-ui-dist to exact version 5.34.0 (no more floating @5).
  • Added integrity="sha384-…" and crossorigin="anonymous" to both the <link> and <script> tags so browsers enforce SRI on CDN assets.
  • Included comments with instructions for recomputing hashes on upgrade.

src/app.ts

  • Updated the stale comment to reflect that the gate lives inside docsRouter.

src/routes/docs.test.ts

  • Added vi.mock so the module-level if-gate evaluates with NODE_ENV="test".
  • Four new assertions: CSS integrity attr, JS integrity attr, crossorigin="anonymous" on both assets, pinned semver format.

src/routes/docs.production.test.ts (new)

  • Separate file so vi.mock hoists before docs.ts loads with NODE_ENV="production".
  • Verifies GET /docs → 404, GET /openapi.json → 200, GET /docs/json → 200.

Tests

12/12 pass across both test files.

Acceptance criteria

…on, add SRI

- Conditionally register GET /docs only when NODE_ENV !== 'production'.
  /openapi.json and /docs/json remain available in all environments.
- Pin swagger-ui-dist to 5.34.0 (exact semver, no floating major).
- Add integrity (sha384) and crossorigin='anonymous' attributes to both
  the <link> and <script> tags so browsers enforce SRI on CDN assets.
- Add comments with instructions for recomputing hashes on version bumps.
- New docs.production.test.ts: verifies /docs → 404 and /openapi.json
  → 200 with NODE_ENV=production (separate file so the vi.mock hoist
  applies to the module-level if-gate in docs.ts).
- Updated docs.test.ts: adds four new assertions for integrity attr,
  crossorigin attr, and pinned semver; existing tests all preserved.
@vercel

vercel Bot commented Oct 20, 2026

Copy link
Copy Markdown

@euniceamoni is attempting to deploy a commit to the work Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@euniceamoni Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Busiii-adetiba
Busiii-adetiba merged commit 2cd5618 into SynapsVault:main Oct 20, 2026
1 of 4 checks passed
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.

Swagger UI is served in every environment, and its CDN assets are unpinned

2 participants