Boundaryby OraXLabs

Boundary by OraXLabs · Public source review · 2026-11-23

Django CSRF
request admission.

Boundary reviewed the actual CSRF middleware and defaults in Django 6.1.3 at a pinned commit. The source separates origin checks from token validation and applies HTTPS Referer checks conditionally. Three documented control observations explain what the code does, its intentional exceptions and the application settings that still need verification. No new Django vulnerability, runtime test or deployment assurance is claimed.

Independent educational review. This work was not commissioned or endorsed by Django. It records existing controls and application checks; it is not a newly disclosed vulnerability.

Executive overview

Use the middleware as a layered control and verify its application/deployment conditions. This selected static review found no supported new vulnerability.

Qualified new vulnerabilities
0
Source control observations
3
Executed tests
0
Remediation status
Not rechecked · No framework patch required by this sample

Scope and method

Release: Django 6.1.3. Snapshot: f16e25dcb9fe55734ba4ea2b00ac34405b7df74a. Review date: 2026-11-23.

We read the selected middleware and global defaults, with the CSRF, cookie, origin and proxy-setting sections of documentation from the same commit. Source bytes were decoded as text and hashed. No target code was imported, evaluated or installed; no tests, browser attacks or live requests were run.

Reviewed files

The settings document was archived for source identity; unrelated settings sections were not reviewed.

Excluded

Pinned source describes selected code, not the safety of all Django behavior or the configuration of a deployed application.

Control observations

These are existing-control observations and integration criteria. Severity is not applicable: no defect or deployed misconfiguration was established.

DJ-CSRF-C01 · Existing control

Unsafe requests pass origin checks and a token check as separate controls

Classification: Source-supported existing control; not a vulnerability. Evidence: Source-supported; deployment conditional.

For non-exempt unsafe methods, process_view checks an available Origin against current scheme/host or configured trusted origins; absent Origin on a secure request invokes strict Referer validation. Both branches proceed to _check_token before acceptance. Matching an allowed origin is not a replacement for a valid token.

Meaning and conditions

The source has layered browser-origin and token admission checks. Coverage depends on middleware/decorator activation, accurate secure-request detection and deliberate trusted-origin configuration.

Source evidence

Counterevidence and limits

Recommended action

Keep unsafe state changes on protected unsafe-method views; verify middleware activation and review exemption/trusted-origin decisions in the actual application.

Verification criterion

Authorized defensive application regression checks should show intended same-origin and trusted-origin unsafe flows require a valid token, and unintended origins or missing/incorrect tokens are rejected. Confirm safe-method handlers are side-effect free.

Status: Not rechecked — static source reading only; no application, HTTP request, browser or tests executed.

DJ-CSRF-C02 · Existing control

Token format validation precedes unmasking and the comparison-helper call

Classification: Source-supported existing control; not a vulnerability. Evidence: Source-supported call path; helper internals not reviewed.

_check_token obtains a cookie/session secret, rejects a missing secret, reads the POST field or configured header, checks token length/allowed characters, and only then calls _does_token_match. That function normalizes masked tokens before delegating comparison to constant_time_compare.

Meaning and conditions

The reviewed caller order respects the normalization function's format assumptions. Masked and unmasked token forms are intentional compatibility behavior; the source compares the underlying secret rather than requiring a stable full masked token.

Source evidence

Counterevidence and limits

Recommended action

Use the framework token mechanism rather than implementing custom masking/comparison; preserve format validation before normalization when extending request handling.

Verification criterion

An authorized project test should cover normal masked/unmasked token acceptance, missing/invalid-format token rejection and the actual form/header path used by the application, without relying on the default CSRF-disabled test client.

Status: Not rechecked — no cryptographic assessment, timing experiment or executed token tests.

DJ-CSRF-C03 · Existing control

Deployment settings determine cookie and HTTPS-related coverage

Classification: Conditional integration checklist; not a discovered Django defect. Evidence: Source-supported defaults and documented conditions.

Cookie issuance uses configured Secure/HttpOnly/SameSite attributes; session-backed CSRF storage requires SessionMiddleware before CsrfViewMiddleware. Global defaults include an empty trusted-origin list, cookie Secure=False, session storage disabled and SECURE_PROXY_SSL_HEADER=None. These are defaults, not evidence of any deployed settings.

Meaning and conditions

The middleware source cannot prove a real site's HTTPS termination, middleware order, trusted subdomain ownership or effective cookie policy. A secure-request classification error can change which documented Referer branch is selected, so proxy trust must be established rather than guessed.

Source evidence

Counterevidence and limits

Recommended action

Inspect the actual project middleware and deployment configuration. For HTTPS deployments choose secure cookie settings and set proxy-header trust only when the controlled proxy strips and sets that header correctly. Minimize trusted origins and document session-backed middleware order where used.

Verification criterion

In an authorized staging environment inspect effective middleware/settings and response-cookie attributes, and establish Django's secure-request classification behind the real proxy. Check project-specific browser CSRF behavior; source defaults alone are insufficient.

Status: Not rechecked — no deployment configuration, proxy, session backend, cookies or live systems were accessed.

Priorities and closure

  1. Review actual middleware activation and exemption decisions (DJ-CSRF-C01).
  2. Check application token integration and format-validation invariants (DJ-CSRF-C02).
  3. Verify effective HTTPS/proxy/cookie/session/trusted-origin settings in authorized staging (DJ-CSRF-C03).

Not rechecked. No patch authored, fixed-in-source or verified-fixed status asserted; follow-up criteria are recommendations, not completed tests.

Source identity

SHA-256 identifies the reviewed bytes. A checksum is not a security certification or proof that an application runs this source.

django/middleware/csrf.py
ae1d82bd6dabbd7f3f67d8294b9f2f2d57a76693fe71edb90f41fd57b6887ebf
django/conf/global_settings.py
3c82ce45a0f468df5daea1b1ff5194e604712477ab8d2d07c267b8acd02e84a5
docs/ref/csrf.txt
75d54fe68f85eaf757838884640ceff90fa9d9df6ef7f867366c160752c30c1f
docs/ref/settings.txt
6d179e8542e023d27078c6eda8af2246c2292d01f5dc5d3618575b95b453ff71

Browse public reviews · Review your public project