Skip to content

Add CSP nonces to the admin layout - #71

Merged
dereuromark merged 1 commit into
masterfrom
csp-script-nonce
Nov 11, 2026
Merged

dereuromark merged 1 commit into
masterfrom
csp-script-nonce

Conversation

@dereuromark

@dereuromark dereuromark commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

CakePHP's CspMiddleware stores its nonces in the cspScriptNonce and cspStyleNonce request attributes. The admin layout read neither, so under a nonce-based policy the CDN Bootstrap script, the CDN stylesheet links and the inline style block were blocked.

Changes:

  • templates/layout/captcha-admin.php: the Bootstrap script gets cspScriptNonce (falling back to cspNonce from a custom middleware). The stylesheet links and the inline style block get cspStyleNonce. Nonces are only emitted when set.
  • CaptchaControllerTest covers the core attributes and the cspNonce fallback.

Follows dereuromark/CakePHP-DatabaseLog#87.

Summary by CodeRabbit

  • Bug Fixes
    • Admin CAPTCHA pages now include configured Content Security Policy nonces on their scripts, styles, and stylesheet links. Script nonce settings also support the existing fallback value, while empty nonce values remain omitted. This helps the page’s assets work with nonce-based security policies.

The admin layout emitted the CDN Bootstrap script, the CDN stylesheet
links and an inline style block without a nonce, so they were blocked
under a nonce-based policy from CakePHP's CspMiddleware. Read
cspScriptNonce (falling back to cspNonce) for the script and
cspStyleNonce for the links and the style block.
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The admin layout now reads CSP script and style nonces from request attributes. It applies them to inline styles, stylesheet links, and the Bootstrap script. Controller tests cover separate nonce attributes and the script nonce fallback.

Changes: Admin CSP nonce rendering

Layer / File(s) Summary
Read and apply CSP nonces
templates/layout/captcha-admin.php, tests/TestCase/Controller/Admin/CaptchaControllerTest.php
The layout applies escaped, non-empty request nonces to the relevant style and script elements. Tests verify separate script and style nonces, the cspNonce script fallback, and request attribute setup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to 03d08

The admin layout now emits CSP nonces on its scripts and styles when they are set, so it works under a nonce-based policy. No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: adding CSP nonces to the admin layout.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bbafd171-524c-4a4e-b623-41ac2d44a268
Commits

Reviewing files that changed from the base of the PR and between a1ebd7d and 03d0877.

Files selected for processing: 2

  • templates/layout/captcha-admin.php
  • tests/TestCase/Controller/Admin/CaptchaControllerTest.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@dereuromark
dereuromark merged commit f05b7e1 into master Nov 11, 2026
21 checks passed
@dereuromark
dereuromark deleted the csp-script-nonce branch November 11, 2026 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant