Skip to content

Commit e47c2ae

Browse files
aspiersclaude
andcommitted
fix(auth-service): make cspNonce required on renderChooseHandlePage
- renderChooseHandlePage: promote cspNonce to a required parameter and always stamp nonce="..." on the inline <script>. All 5 call sites already pass res.locals.cspNonce, so the previous `cspNonce?` + conditional fallback only served to mask a future wiring bug where a caller forgot the nonce — the CSP is now nonce-based, so missing nonce means broken page, not graceful degradation. - preview-ui: reword renderPreviewIndexPage cspNonce docstring. pds-core does serve at least one preview page (/preview/consent) under a CSP with 'unsafe-inline', so "omit when the service doesn't set a CSP" was misleading; frame the rule around the page's CSP rather than the service. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 4a2f31d commit e47c2ae

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

packages/auth-service/src/routes/choose-handle.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,11 @@ export function createChooseHandleRouter(
438438

439439
export function renderChooseHandlePage(
440440
handleDomain: string,
441-
error?: string,
442-
csrfToken?: string,
443-
showRandomButton?: boolean,
444-
customCss?: string | null,
445-
cspNonce?: string,
441+
error: string | undefined,
442+
csrfToken: string | undefined,
443+
showRandomButton: boolean,
444+
customCss: string | null,
445+
cspNonce: string,
446446
): string {
447447
const errorHtml = error
448448
? `<div class="error" id="error-msg">${escapeHtml(error)}</div>`
@@ -518,7 +518,7 @@ export function renderChooseHandlePage(
518518
</form>
519519
</div>
520520
521-
<script${cspNonce ? ` nonce="${escapeHtml(cspNonce)}"` : ''}>
521+
<script nonce="${escapeHtml(cspNonce)}">
522522
(function() {
523523
var input = document.getElementById('handle-input');
524524
var statusEl = document.getElementById('handle-status');

packages/shared/src/preview-ui.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,11 @@ export function renderPreviewIndexPage(opts: {
181181
authPublicUrl: string
182182
pdsPublicUrl: string
183183
/**
184-
* CSP nonce to stamp on the inline <script>. Required on services that
185-
* emit a `script-src 'nonce-...'` CSP (auth-service); omit on services
186-
* that don't set a CSP (pds-core).
184+
* CSP nonce to stamp on the inline <script>. Required when this preview
185+
* index is served with a `script-src 'nonce-...'` CSP (e.g. auth-service);
186+
* omit when it's served with a policy that permits inline scripts
187+
* without a nonce (e.g. pds-core's `/preview` index, which doesn't set
188+
* a CSP at all, or any page served with `script-src ... 'unsafe-inline'`).
187189
*/
188190
cspNonce?: string
189191
}): string {

0 commit comments

Comments
 (0)