Built-in error pages don't carry the request's CSP nonce, so a strict policy blocks their styles and script

Open
#871 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
backend, security

Research direction

Start with crates/http/src/errors/page.rs and crates/http/src/errors/renderer/page.html, where the built-in pages are rendered. Check how view::use_csp_nonce exposes the request nonce and how vite() applies it; done when both error pages include the nonce on inline style and script tags when set, and remain unchanged without one. The issue author says a PR is ready.

Written by the indexing model from the issue text.

Description

The problem

view::use_csp_nonce gives every tag that vite() and vite_react_refresh() render the request's nonce (#374), and the templates guide shows a middleware that sends script-src 'nonce-…' 'strict-dynamic'; style-src 'nonce-…'. The built-in error pages don't use that nonce:

So with the policy from the guide, any error that reaches the built-in pages renders as unstyled HTML, and the debug page's highlighting script is blocked. The application can't fix it from outside: the page is rendered by the framework, and the only way around it is to drop the policy for error responses.

To reproduce, add the middleware from the templates guide ("Content Security Policy nonces") to a new app with APP_DEBUG=true, and return Err(laravel::Error::msg("boom")) from a handler. The browser blocks the page's three inline tags, so it shows unstyled markup and no highlighting.

Proposal

Render the request's nonce on the inline <style> and <script> tags of both built-in pages when one is set, the same way vite() does, and leave the pages unchanged when no nonce is set. Error responses already pass back through the middleware that set the nonce and adds the header, so the nonce and the policy match.

Laravel Classic's renderer inlines its CSS and JS without a nonce too (Renderer::css() and Renderer::js()), but here the nonce is already request-scoped and available where the page is rendered, so the fix is small.

Use case

An operations dashboard or any app that ships a strict CSP in every environment, so that a policy violation shows up during development rather than in production. Today such an app has to exempt error responses from its policy, or accept unreadable error pages while developing.

I have a PR ready for this.

Dominant language
Rust
Stars
847
Forks
174
Avg merge
5h 40m
Merged PRs (30d)
167

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from laravel/rust-framework

All issues in laravel/rust-framework

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.