Skip to content

Harden CSP and add password strength meter#32

Merged
sidhujag merged 4 commits intomasterfrom
harden/csp-password-strength-meter
Apr 25, 2026
Merged

Harden CSP and add password strength meter#32
sidhujag merged 4 commits intomasterfrom
harden/csp-password-strength-meter

Conversation

@sidhujag
Copy link
Copy Markdown
Member

Summary

  • Tighten the frontend CSP so connect-src defaults to same-origin only and filters wildcard HTTP(S)/WS sources from SYSNODE_CSP_CONNECT_SRC.
  • Replace the simple 8+3 password-class rule with zxcvbn-backed strength estimation while keeping the 8-character minimum.
  • Add a visible password strength meter and feedback on register/change-password, including tests for common-password rejection and passphrase/generated-password acceptance.

Test plan

  • npm test -- --watchAll=false src/lib/passwordPolicy.test.js src/pages/Register.test.js src/components/ChangePasswordCard.test.js src/lib/apiClient.test.js
  • ReadLints on changed files
  • curl -I https://sysnode.dev11.top/ verified live HSTS is already present

Notes

  • Local npm run build still fails with the existing local Unexpected end of JSON input issue seen on prior branches; CI build remains the authoritative build check.

Made with Cursor

Use estimator-based password validation so short-but-strong generated passwords can pass while common weak passwords are rejected, and remove wildcard HTTPS connect-src from the key-custody SPA CSP.

Made-with: Cursor
@sidhujag
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0547395586

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment thread server.js
Comment on lines 26 to +30
"'self'",
'https:',
...splitCspSources(process.env.SYSNODE_CSP_CONNECT_SRC),
// Key-custody pages must not allow arbitrary HTTPS exfiltration. Keep
// production same-origin by default; deployments that truly need another
// endpoint can add exact origins via SYSNODE_CSP_CONNECT_SRC.
...explicitConnectSources(process.env.SYSNODE_CSP_CONNECT_SRC),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Allow default API origin in connect-src

connect-src now resolves to 'self' plus optional SYSNODE_CSP_CONNECT_SRC, but the app’s anonymous client still defaults production traffic to https://syscoin.dev (see src/lib/api.js), so default builds with no extra CSP env will have browser-blocked fetch calls for network/governance data. This regresses the out-of-the-box production path unless deployers add a second, synchronized env var; the policy should include the default API origin (or derive allowed origins from the API base setting) to avoid breaking those pages.

Useful? React with 👍 / 👎.

Comment thread src/lib/passwordPolicy.js Outdated
Comment on lines +18 to +20
return (Array.isArray(userInputs) ? userInputs : [])
.map((value) => String(value || '').trim())
.filter(Boolean);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Tokenize user inputs before feeding zxcvbn

normalizeUserInputs forwards each provided value as a single dictionary entry, and call sites pass only the full email string, so passwords containing just the local-part (or other email fragments) are not penalized by the user-input dictionary as intended. In practice this weakens the new “personal info” hardening for values like alice2026! with alice@example.com; split/expand user inputs into meaningful tokens before calling zxcvbn.

Useful? React with 👍 / 👎.

Preserve the exact default public API origin in connect-src and expand user identity inputs into useful zxcvbn dictionary tokens.

Made-with: Cursor
@sidhujag
Copy link
Copy Markdown
Member Author

@codex review

Addressed the previous inline findings:

  • now includes the exact default public API origin used by ( origin, or in production) while still filtering wildcard schemes from .
  • zxcvbn user inputs now expand email/full identity strings into local-part/domain/alphanumeric tokens so passwords based on email fragments are penalized.

Note: no forward DB migration is needed for this app before production; schema changes on this pre-production line should be reviewed as direct initial-schema changes when applicable.

@sidhujag
Copy link
Copy Markdown
Member Author

@codex review

Addressed the previous inline findings:

  • connect-src now includes the exact default public API origin used by src/lib/api.js (REACT_APP_API_BASE origin, or https://syscoin.dev in production) while still filtering wildcard schemes from SYSNODE_CSP_CONNECT_SRC.
  • zxcvbn user inputs now expand email/full identity strings into local-part/domain/alphanumeric tokens so passwords based on email fragments are penalized.

Note: no forward DB migration is needed for this app before production; schema changes on this pre-production line should be reviewed as direct initial-schema changes when applicable.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 237c186336

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment thread server.js Outdated
Comment on lines +34 to +36
const defaultPublicApiBase =
process.env.REACT_APP_API_BASE ||
(process.env.NODE_ENV === 'production'
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep connect-src in sync with build-time API base

defaultPublicApiBase is derived from process.env.REACT_APP_API_BASE at server runtime, but the frontend API base in src/lib/api.js is baked in at build time; when a build is produced with REACT_APP_API_BASE set (documented workflow) and deployed without the same runtime env, CSP falls back to https://syscoin.dev while the bundle still calls the custom origin, so connect-src blocks all anonymous API requests in production. Please derive the allowlisted origin from the build-time value (or otherwise guarantee both values are emitted together) so the policy cannot drift.

Useful? React with 👍 / 👎.

Avoid CSP drift from build-time API overrides by making production clients use relative same-origin paths and limiting explicit API base overrides to non-production builds.

Made-with: Cursor
@sidhujag
Copy link
Copy Markdown
Member Author

@codex review

Addressed the latest P1 by removing production build/runtime API-base drift entirely:

  • production anonymous and authenticated clients now use same-origin relative API paths, matching the selected deployment model and CSP self policy;
  • REACT_APP_API_BASE remains only for non-production/local testing;
  • README now documents production reverse-proxy same-origin deployment instead of cross-origin production builds.

The previous zxcvbn tokenization fix is still included.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 942421a192

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment thread README.md
@@ -38,13 +38,15 @@ https://sysnode.info/vault/* -> backend
https://sysnode.info/gov/* -> backend
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Route anonymous API paths through production proxy map

The same-origin deployment map now lists only /auth/*, /vault/*, and /gov/*, but this commit also changed production anonymous calls to same-origin '/mnStats', '/mnCount', and '/govlist' (src/lib/api.js). If operators follow this README block literally, those anonymous endpoints are not proxied to the backend, so public dashboard data requests will hit the SPA server (GETs return index.html, POST /govlist fails), breaking core data views in production.

Useful? React with 👍 / 👎.

Comment thread README.md Outdated
For local or non-production testing, you can override the API base URL at build time:

```bash
REACT_APP_API_BASE=https://your-backend.example npm run build
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use non-production command for API base override example

The example REACT_APP_API_BASE=... npm run build is inconsistent with the new runtime logic: both clients now ignore REACT_APP_API_BASE when NODE_ENV === 'production' (src/lib/apiClient.js and src/lib/api.js). That means readers who use this documented command won’t get the override they expect, which is likely to cause confusing misconfiguration during local/staging tests.

Useful? React with 👍 / 👎.

Document the anonymous API routes required by production same-origin deployments and use a dev-server example for non-production API base overrides.

Made-with: Cursor
@sidhujag
Copy link
Copy Markdown
Member Author

@codex review

Addressed the latest README findings:

  • production same-origin proxy map now includes the anonymous API endpoints used by src/lib/api.js: /mnStats, /mnCount, and /govlist;
  • API base override example now uses the dev server instead of a production build, matching the production same-origin rule.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@sidhujag sidhujag merged commit 3294fee into master Apr 25, 2026
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.

1 participant