Skip to content

Pyjoyment.Plugin.SecurityHeaders: reports, the route of the reports of CSP - #639

Merged
dex4er merged 1 commit into
security-headers-noncefrom
security-headers-reports
Nov 18, 2026
Merged

dex4er merged 1 commit into
security-headers-noncefrom
security-headers-reports

Conversation

@dex4er

@dex4er dex4er commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Part of #634, its fourth step, stacked on #638.

Changes

  • New option reports, the path of a route named csp_reports:
    • Policies of csp and csp_report_only given as dicts, which have no report-uri or report-to of their own, get report-uri (for browsers without the Reporting API) and report-to csp. Responses get Reporting-Endpoints: csp="…". A policy with its own endpoint, or one given as a string, is kept as it is.
    • The URL comes from url_for('csp_reports') for each response, so it carries the prefix of an application mounted with Mount.
    • The route takes both formats: the object csp-report of report-uri and the array of the Reporting API, of which only type: csp-violation is used. It turns both into the body of a report of the Reporting API (documentURL, blockedURL, effectiveDirective, disposition, …), logs each violation with warn, emits the hook csp_report(c, report), and answers 204. A body that is not a report gets 400.
    • The log line has its control characters replaced and each value cut to 200 characters, as a client can send anything to the public route.
  • New option max_report_size, 64 KiB by default; a larger body gets 413.

Validation

  • t/Pyjoyment/security_headers_lite_app.py, subtest Reports:
    • the headers with the endpoint
    • a report of report-uri and its renamed fields; the reports of report-to, without the other types
    • the log against forgery (a newline, a value of 1000 characters)
    • 400 for bodies that are not reports, 404 for GET, 413 over the limit
    • policies with their own endpoint or given as a string are kept
    • with the nonce and with options of a route
    • an application mounted under /app
  • t/docs/Pyjoyment_Plugin_SecurityHeaders.py: the examples of reports, max_report_size and the hook csp_report
  • pyright strict: 0 errors
  • PYTHONDEVMODE=1 python -m Pyjo.Prove -l -j 4 -r t on asyncio and on Pyjo.Reactor.Poll: all tests pass
  • sphinx-build -W passes
  • trunk check: no issues
  • CI

🤖 Generated with Claude Code

…f CSP

The option reports adds a route that takes the reports of report-uri and
of report-to, logs each violation and emits the hook csp_report, and puts
report-uri and report-to into the policies of a dict without them, with
Reporting-Endpoints, with the prefix of an application that is mounted.
max_report_size limits the body.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dex4er dex4er added this to the 0.4.1 milestone Nov 18, 2026
@dex4er
dex4er added this pull request to stack #637 November 18, 2026 17:09
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 Pyjoyment | 🛠️ Build #35990895 | 📁 Comparing 2cda4e0 against latest (4deb3f0)

  🔍 Preview build  

7 files changed · + 1 added · ± 6 modified

+ Added

± Modified

@github-actions

Copy link
Copy Markdown
Contributor

Docker Smoke Test

Job Tests Passed ✅ Skipped ⚠️ Failed ❌ Log
smoke (app) 11 11 0 0 ✅ 134982478128
smoke (fastcgi) 5 5 0 0 ✅ 134982478034
smoke (kubernetes) 8 8 0 0 ✅ 134982478140
smoke (lambda) 2 2 0 0 ✅ 134982478148
smoke (lambda-image) 5 5 0 0 ✅ 134982478094
smoke (lambda-stream) 2 2 0 0 ✅ 134982478064
smoke (lambda-zip) 9 9 0 0 ✅ 134982478177
smoke (lite) 4 4 0 0 ✅ 134982477470
smoke (lite-pep723) 4 4 0 0 ✅ 134982478085
All 50 50 0 0 ✅

The run of the workflow

@github-actions

Copy link
Copy Markdown
Contributor

Tests

Job Tests Passed ✅ Skipped ⚠️ Failed ❌ Log
prove (python 3.12, Asyncio) 7498 7469 29 0 ✅ 134982480107
prove (python 3.12, Poll) 7470 7439 31 0 ✅ 134982479842
prove (python 3.13, Asyncio) 7498 7469 29 0 ✅ 134982479688
prove (python 3.13, Poll) 7470 7439 31 0 ✅ 134982480149
prove (python 3.14, Asyncio) 7529 7505 24 0 ✅ 134982480189
prove (python 3.14, Poll) 7501 7475 26 0 ✅ 134982480150
prove (python 3.15, Asyncio) 7529 7505 24 0 ✅ 134982480064
prove (python 3.15, Poll) 7501 7475 26 0 ✅ 134982479996
prove (python 3.15t, Asyncio) 7529 7505 24 0 ✅ 134982480438
prove (python 3.15t, Poll) 7501 7475 26 0 ✅ 134982480086
prove (python mise, Asyncio) 7608 7573 35 0 ✅ 134982479392
prove (python mise, Asyncio, Windows) 7329 7263 66 0 ✅ 134982479174
prove (python mise, Poll) 7580 7543 37 0 ✅ 134982479639
prove (python mise, Poll, Windows) 7301 7233 68 0 ✅ 134982479301
prove (python pypy3.12, Asyncio) 7498 7469 29 0 ✅ 134982480134
prove (python pypy3.12, Poll) 7470 7439 31 0 ✅ 134982480091
pytest (python 3.12, ubuntu-26.04-arm) 444 418 26 0 ✅ 134982479338
pytest (python 3.15, ubuntu-26.04-arm) 444 423 21 0 ✅ 134982479185
pytest (python 3.15, windows-2025) 444 395 49 0 ✅ 134982479497
servers (python 3.12) 54 54 0 0 ✅ 134982478526
servers (python 3.15) 53 53 0 0 ✅ 134982479191
All 121251 120619 632 0 ✅

The run of the workflow

@dex4er dex4er modified the milestones: 0.4.1, 0.5.0 Nov 18, 2026
@dex4er
dex4er merged commit de035a8 into main Nov 18, 2026
36 checks passed
@dex4er
dex4er deleted the security-headers-reports branch November 18, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant