-
Notifications
You must be signed in to change notification settings - Fork 0
Harden CSP and add password strength meter #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,10 +16,18 @@ function uniqueSources(sources) { | |
| return [...new Set(sources.filter(Boolean))]; | ||
| } | ||
|
|
||
| function explicitConnectSources(value) { | ||
| return splitCspSources(value).filter( | ||
| (source) => !['*', 'http:', 'https:', 'ws:', 'wss:'].includes(source) | ||
| ); | ||
| } | ||
|
|
||
| const connectSrc = uniqueSources([ | ||
| "'self'", | ||
| 'https:', | ||
| ...splitCspSources(process.env.SYSNODE_CSP_CONNECT_SRC), | ||
| // Key-custody pages must not allow arbitrary HTTPS exfiltration. Production | ||
| // API traffic is 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), | ||
|
Comment on lines
26
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| ]); | ||
|
|
||
| // HSTS is owned in code so any deployer (behind nginx, Caddy, a managed load | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import React, { useMemo } from 'react'; | ||
|
|
||
| import { | ||
| estimateVaultPasswordStrength, | ||
| MIN_VAULT_PASSWORD_LENGTH, | ||
| MIN_VAULT_PASSWORD_SCORE, | ||
| passwordStrengthFeedback, | ||
| passwordStrengthLabel, | ||
| VAULT_PASSWORD_HINT, | ||
| } from '../lib/passwordPolicy'; | ||
|
|
||
| export default function PasswordStrengthMeter({ | ||
| password, | ||
| userInputs, | ||
| id, | ||
| describedBy, | ||
| }) { | ||
| const result = useMemo( | ||
| () => estimateVaultPasswordStrength(password, userInputs), | ||
| [password, userInputs] | ||
| ); | ||
| const hasPassword = typeof password === 'string' && password.length > 0; | ||
| const lengthOk = hasPassword && password.length >= MIN_VAULT_PASSWORD_LENGTH; | ||
| const scoreOk = lengthOk && result.score >= MIN_VAULT_PASSWORD_SCORE; | ||
| const label = hasPassword ? passwordStrengthLabel(result.score) : 'Start typing'; | ||
| const feedback = !hasPassword | ||
| ? VAULT_PASSWORD_HINT | ||
| : !lengthOk | ||
| ? `Use at least ${MIN_VAULT_PASSWORD_LENGTH} characters.` | ||
| : scoreOk | ||
| ? 'Looks strong enough for vault encryption.' | ||
| : passwordStrengthFeedback(result); | ||
|
|
||
| return ( | ||
| <div | ||
| className="password-meter" | ||
| data-score={hasPassword ? result.score : -1} | ||
| data-valid={scoreOk ? 'true' : 'false'} | ||
| id={id} | ||
| aria-describedby={describedBy} | ||
| > | ||
| <div className="password-meter__topline"> | ||
| <span>Password strength</span> | ||
| <strong>{label}</strong> | ||
| </div> | ||
| <div | ||
| className="password-meter__track" | ||
| role="meter" | ||
| aria-valuemin={0} | ||
| aria-valuemax={4} | ||
| aria-valuenow={hasPassword ? result.score : 0} | ||
| aria-valuetext={label} | ||
| > | ||
| <span | ||
| className="password-meter__bar" | ||
| style={{ width: `${hasPassword ? ((result.score + 1) / 5) * 100 : 0}%` }} | ||
| /> | ||
| </div> | ||
| <p className="password-meter__feedback">{feedback}</p> | ||
| </div> | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 returnindex.html, POST/govlistfails), breaking core data views in production.Useful? React with 👍 / 👎.