Skip to content

fix(web): require POST with CSRF for actions and reveal secrets on demand - #789

Open
Seme30 wants to merge 2 commits into
devfrom
fix/state-changing-get-requests
Open

Seme30 wants to merge 2 commits into
devfrom
fix/state-changing-get-requests

Conversation

@Seme30

@Seme30 Seme30 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Hub stores credentials for other systems, so two web issues mattered:

  • Actions ran on GET. Deletes, run, disable, duplicate, reset and the scheduler controls were plain links, so a crafted link or a browser prefetch could perform them as the signed-in user.
  • Secrets were in every page. Connection passwords, keys, connection strings and "sensitive" parameters were decrypted into the HTML, even when hidden.

Changes

  • 34 state-changing routes are POST-only, so Hub's existing CSRFProtect now checks them. A GET returns 405; a POST without the token returns 400.
  • Buttons keep their markup. Each page gets a csrf-token meta tag (outside the shared {% cache %} block), and data-method="post" links submit as a form with the token. Confirms moved to data-confirm, so cancelling can't still submit. The enable/disable switch sends the token as a header.
  • New POST /secret/<kind>/<id>/<field> reveals or copies one secret. Each use is logged to Admin → User History (never the value), and responses are Cache-Control: no-store.
  • Connection, project and task pages no longer contain decrypted secrets. They show a masked value with Show and Copy; Show hides again after 30 seconds. Connection strings stay readable except the password.
  • Removed the database_pass filter (it put the password in the page twice) and the "Toggle Sensitive Values" block.

Not in this PR: edit forms still prefill decrypted values. That needs "leave blank to keep the current value" in each save handler, so it's a separate change.

Screenshots

Same demo data on dev (before) and this branch (after).

Before After
Connection page Connection page before Connection page after
Task page Task page before Task page after
Project page Project page before Looks the same as before. Toggle Sensitive Values now fetches the values when clicked, instead of them being hidden in the page.

After clicking Show (hides again after 30 seconds):

Password revealed after clicking Show

Test plan

  • pytest web/tests: 193 passed, including new tests in test_post_actions_and_secrets.py:
    • all 34 routes reject GET
    • each route works by POST
    • a tokenless POST is rejected
    • reveal and copy return the value, log the access and send no-store
    • pages don't contain secrets
  • ruff, ruff format, mypy, djlint and biome pass.
  • Checked in the running app with CSRF on: Show and Copy work and are logged, Duplicate and the enable switch work by POST, GET returns 405 and a tokenless POST returns 400.
  • Reviewer: try Delete and Run from a connection and a task page.

@gitguardian

gitguardian Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.91%. Comparing base (8425b12) to head (30d5eac).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #789      +/-   ##
==========================================
+ Coverage   71.64%   72.91%   +1.26%     
==========================================
  Files          41       42       +1     
  Lines        5382     5409      +27     
  Branches      492      493       +1     
==========================================
+ Hits         3856     3944      +88     
+ Misses       1414     1347      -67     
- Partials      112      118       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…mand

Actions that change data were plain GET links, so a crafted link or a
browser prefetch could delete a connection, run a task or stop the
scheduler as the signed-in user. Stored secrets were also decrypted
into every connection, project and task page.

- Make 34 state-changing routes POST-only (deletes, run, schedule,
  enable, disable, duplicate, reset, end retry, refresh cache, file
  sends, dashboard bulk actions and scheduler controls). Hub's
  CSRFProtect now checks them.
- Add a csrf-token meta tag and submit data-method="post" links as a
  form with the token; the enable/disable switch sends it as a header.
- Add POST /secret/<kind>/<id>/<field> to reveal or copy one secret.
  Each use is written to the user history log, never the value, and
  the response is sent with Cache-Control: no-store.
- Stop rendering decrypted passwords, keys, connection strings and
  sensitive parameters on connection, project and task pages. Show a
  masked value with Show and Copy instead; connection strings keep
  everything but the password visible.
- Remove the database_pass filter, which put the password in the page
  twice, and the "Toggle Sensitive Values" block.
- Update tests that called these routes with GET, and add tests for
  POST-only routes, CSRF, the reveal endpoint and masking.

Edit forms still prefill decrypted values; that needs a "leave blank
to keep" change and is left for a follow-up.
@Seme30
Seme30 force-pushed the fix/state-changing-get-requests branch from 2791ad5 to 29ecbca Compare December 1, 2026 09:47
- Show connection strings and SSH/GPG keys in the Prism-highlighted code
  box again, with Show and Copy below; revealed values are highlighted.
- Restore the "Toggle Sensitive Values" button and ini block for project
  and task parameters. The button now fetches sensitive values on demand
  (logged), and hides them again after 30 seconds.

This branch has not been deployed

No deployments
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