Skip to content

Commit 2ceaded

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 82e5bf3 commit 2ceaded

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -450,13 +450,13 @@ export function createChooseHandleRouter(
450450

451451
export function renderChooseHandlePage(
452452
handleDomain: string,
453-
error?: string,
454-
csrfToken?: string,
455-
showRandomButton?: boolean,
456-
customCss?: string | null,
457-
customFaviconUrl?: string | null,
458-
customFaviconUrlDark?: string | null,
459-
cspNonce?: string,
453+
error: string | undefined,
454+
csrfToken: string | undefined,
455+
showRandomButton: boolean,
456+
customCss: string | null,
457+
customFaviconUrl: string | null,
458+
customFaviconUrlDark: string | null,
459+
cspNonce: string,
460460
): string {
461461
const errorHtml = error
462462
? `<div class="error" id="error-msg">${escapeHtml(error)}</div>`
@@ -533,7 +533,7 @@ export function renderChooseHandlePage(
533533
</form>
534534
</div>
535535
536-
<script${cspNonce ? ` nonce="${escapeHtml(cspNonce)}"` : ''}>
536+
<script nonce="${escapeHtml(cspNonce)}">
537537
(function() {
538538
var input = document.getElementById('handle-input');
539539
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
@@ -357,9 +357,11 @@ export function renderPreviewIndexPage(opts: {
357357
authPublicUrl: string
358358
pdsPublicUrl: string
359359
/**
360-
* CSP nonce to stamp on the inline <script>. Required on services that
361-
* emit a `script-src 'nonce-...'` CSP (auth-service); omit on services
362-
* that don't set a CSP (pds-core).
360+
* CSP nonce to stamp on the inline <script>. Required when this preview
361+
* index is served with a `script-src 'nonce-...'` CSP (e.g. auth-service);
362+
* omit when it's served with a policy that permits inline scripts
363+
* without a nonce (e.g. pds-core's `/preview` index, which doesn't set
364+
* a CSP at all, or any page served with `script-src ... 'unsafe-inline'`).
363365
*/
364366
cspNonce?: string
365367
}): string {

0 commit comments

Comments
 (0)