harden: make every whitelisted write POST-only - #433
Merged
Conversation
A whitelisted method with no `methods` accepts GET, which puts it one cross-site
request away from being fired by any page the victim happens to visit. Eleven of
Draw's write endpoints were in that state while the rest of the app was already
POST-only:
share.py share_diagram, unshare_diagram, set_general_access, set_public
comment.py add_comment, reply_comment, edit_comment, resolve_comment,
delete_comment
drive_integration.py add_to_drive, move_to_drive_folder
Sharing is the worst of them. A forged request there grants the attacker
standing access to the document rather than damaging it once, and it is the one
write whose effect outlives the session it was made in.
Nothing persisted today, because Frappe rolls a GET back at the end of the
request. That is a property of the transaction handler rather than of these
modules, and diagram.py has already had a manual commit turn exactly this shape
into a live CSRF write vector — the comment above save_diagram records it. The
rule is worth holding whether or not the current default saves us.
No client changes: frappe-ui's `call()` posts, which is how all eleven are
reached.
Guarded by a signature test alongside the annotation one, for the same reason —
an in-process call cannot see which verbs an endpoint would accept over HTTP, so
this class of defect is invisible to every other test in the file.
Found while auditing sharing for #422.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while auditing sharing for #422. It is not a sharing problem, which is why it is not in that PR.
The gap
A whitelisted method with no
methodsaccepts GET. That puts it one cross-site request away from being fired by any page the victim happens to visit — no form, no fetch, an<img src>is enough. Eleven of Draw's write endpoints were in that state while the rest of the app was already POST-only:share.pyshare_diagram,unshare_diagram,set_general_access,set_publiccomment.pyadd_comment,reply_comment,edit_comment,resolve_comment,delete_commentdrive_integration.pyadd_to_drive,move_to_drive_folderSharing is the worst of them. A forged request there grants the attacker standing access to the document rather than damaging it once, and it is the one write whose effect outlives the session that made it.
share_diagram(name, user, level)takes only values an attacker already knows or chooses.Why it did not bite
Frappe rolls a GET back at the end of the request, so nothing persisted. Worth being precise that this is a property of the transaction handler, not of these modules — and that
diagram.pyhas already had a manualfrappe.db.commit()turn exactly this shape into a live CSRF write vector. The comment abovesave_diagramstill records it:One
commit()added to any of these paths, for any reason, and the rollback stops covering us. The rule is worth holding whether or not today's default saves us.No client changes
frappe-ui's
call()setsmethod: 'POST'(utils/call.js:21), which is how all eleven are reached. Verified against the call sites inuseComments.js,useShare.js,DriveMenu.vueanddata/drive.js.The guard
A signature test sits beside the existing annotation one and for the same reason: an in-process call cannot see which verbs an endpoint would accept over HTTP, so this whole class is invisible to every other test in the file. It walks the app's AST, takes every whitelisted function whose name starts with a mutating verb, and fails any that accepts GET.
That heuristic is deliberately name-based rather than a hand-written list — a new
delete_collectionorset_whateveris caught the day it is written, without anyone remembering this PR.What I did NOT change
The rest of the sharing audit came out clean and is left alone: every mutation checks
has_permission(..., "share"), share targets are validated against real enabled users,search_usersescapes LIKE wildcards and refuses queries under two characters, and both the access level and the general-access tier are checked against allowlists. No raw SQL anywhere in the module.set_publicis dead — no caller outside a test that documents it as a shim for older clients. It is POST-restricted here rather than removed, since deleting a whitelisted endpoint is an API breaking change and worth deciding separately.Test plan
bench --site test.localhost run-tests --app draw --module draw.draw.doctype.draw_diagram.test_draw_diagram— 76 tests, 1 newtest_diagram_drive_path_degrades_without_raising_on_a_broken_drive) is pre-existing and environment-specific — a danglingsuiteentry in this bench'sapps.txt. It passes in CI.🤖 Generated with Claude Code