Opened 2 months ago

Closed 2 months ago

Last modified 2 months ago

#37119 closed Cleanup/optimization (fixed)

Adjust CSP middleware ordering note to clarify the effect of "accessing" the nonce

Reported by: Jacob Walls Owned by: Vishy
Component: Documentation Version: 6.0
Severity: Normal Keywords: CSP
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

See discussion on a closed PR. Our middleware ordering advice says this about ContentSecurityPolicyMiddleware:

Can be placed near the bottom, but ensure any middleware that accesses csp_nonce is positioned after it, so the nonce is properly included in the response header.

To my ear, this assumes too much knowledge about the underlying "lazy" implementation that waits to materialize a nonce until it is "accessed". Without that detail in mind, on first read, I thought this was referring to accessing the header, which made me think this advice was backwards (to access the header, a response-phase middleware would need to be ordered before, not after).

Suggested edit to clarify the laziness, and that "accessing" refers to the nonce value, not the header:

-   Can be placed near the bottom, but ensure any middleware that accesses
-   :ref:`csp_nonce <csp-nonce>` is positioned after it, so the nonce is
-   properly included in the response header.
+   Can be placed near the bottom, but since the :ref:`csp_nonce <csp-nonce>` is
+   lazy, ensure any middleware that accesses it is positioned after, so the
+   nonce is generated before this middleware builds the response header.

Change History (6)

comment:1 by Vishy, 2 months ago

Owner: set to Vishy
Status: newassigned

comment:2 by Tim Graham, 2 months ago

Triage Stage: UnreviewedAccepted

comment:3 by Vishy, 2 months ago

Has patch: set

comment:4 by Jacob Walls, 2 months ago

Triage Stage: AcceptedReady for checkin

comment:5 by Jacob Walls <jacobtylerwalls@…>, 2 months ago

Resolution: fixed
Status: assignedclosed

In be8d1b62:

Fixed #37119 -- Clarified middleware ordering note for nonce access.

comment:6 by Jacob Walls <jacobtylerwalls@…>, 2 months ago

In 2399b9e:

[6.1.x] Fixed #37119 -- Clarified middleware ordering note for nonce access.

Backport of be8d1b628533ac38d2771356e92ade1d61d3f059 from main.

Note: See TracTickets for help on using tickets.
Back to Top