Skip to content

fix(core): require POST for state-changing actions (CSRF hardening) - #8609

Open
somethingwithproof wants to merge 73 commits into
developfrom
fix/csrf-require-post-on-state-change
Open

somethingwithproof wants to merge 73 commits into
developfrom
fix/csrf-require-post-on-state-change

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

This combines the three require-POST hardening batches into one branch. State-changing requests now reach their handlers only by POST with a valid token, and a GET to the same action is refused.

From #8609 (batch 1): the bulk-action execute branch of form_actions() in 17 core pages (aggregate graphs and templates, CDEFs, colors and color templates, data input, data queries, data source profiles, data sources, data templates, GPRINT presets, graph templates, graphs, device templates, pollers, sites and VDEFs) calls csrf_require_post(). It also adds the isolated probe and coverage fixtures that exercise each handler by GET, by tokenless POST and by valid POST, plus the CI fixes those probes needed.

From #8611 (batch 2): the same guard on the bulk-action execute branch of host.php, layouts.php, lib/html_reports.php, links.php, login_providers.php, managers.php, package_keys.php, package_repos.php, tree.php, user_admin.php and user_group_admin.php, with administration coverage fixtures and a crawl log filter for routine audit purge notes. Its CI and test-helper commits were identical to the ones from #8609, so they are carried once.

From #8613 (batch 3): form_save(), the automation form_actions() handlers and the POST-only direct actions (reordering, item moves and removals, drag-and-drop) in 30 pages call csrf_require_post(). The POST transport map in include/layout.js lists the newly guarded tree, links and automation actions, so the UI sends them by POST. A transport map test fails when a guarded action is still requested by GET, and a per-file probe covers each new guard.

Supersedes #8611, #8613.

Merge order: this PR and #8622 change layouts.php, this PR and #8704 change data_sources.php, and this PR and #8540 both add tests/e2e/tests/post-action-transport.spec.js. Suggested order: this PR first in each case, then #8622, #8704 and #8540. This PR and #8823 change the same lines of auth_profile.php, automation_templates.php and graph_templates.php in different ways, so no order is suggested between them; they need to be reconciled. Whichever merges later will be rebased.

@somethingwithproof
somethingwithproof requested a review from a team as a code owner November 6, 2026 08:58
@somethingwithproof
somethingwithproof requested review from TheWitness and removed request for a team November 6, 2026 08:58
@somethingwithproof
somethingwithproof force-pushed the fix/csrf-require-post-on-state-change branch from 1a6b6ed to f4d7bb0 Compare November 9, 2026 05:24
@github-actions
github-actions Bot force-pushed the fix/csrf-require-post-on-state-change branch 4 times, most recently from 3052c58 to 67aa5f6 Compare November 11, 2026 21:08
@somethingwithproof
somethingwithproof force-pushed the fix/csrf-require-post-on-state-change branch from 67aa5f6 to 52a1068 Compare November 12, 2026 07:51
@somethingwithproof somethingwithproof changed the title security(core): require POST on form_actions bulk-action execute branch (CSRF-on-GET) fix(core): require POST for state-changing actions (CSRF hardening) Nov 12, 2026
@somethingwithproof somethingwithproof added this to the v1.3.0 milestone Nov 13, 2026
@somethingwithproof somethingwithproof added bug Undesired behaviour core/config A core feature either system level or config labels Nov 13, 2026
@github-actions
github-actions Bot force-pushed the fix/csrf-require-post-on-state-change branch 4 times, most recently from 24c1434 to 2b8c82e Compare November 17, 2026 08:47
@somethingwithproof somethingwithproof added the release:1.3 Namespaced Cacti workflow label label Nov 17, 2026
@somethingwithproof
somethingwithproof force-pushed the fix/csrf-require-post-on-state-change branch 2 times, most recently from 4e4d485 to cf6e1a4 Compare November 19, 2026 09:34
@github-actions
github-actions Bot force-pushed the fix/csrf-require-post-on-state-change branch from cf6e1a4 to 8fe3d51 Compare November 19, 2026 20:50
@somethingwithproof
somethingwithproof force-pushed the fix/csrf-require-post-on-state-change branch from b9e6645 to 2ed4a2b Compare November 25, 2026 08:03
@github-actions
github-actions Bot force-pushed the fix/csrf-require-post-on-state-change branch from 2ed4a2b to 48a7341 Compare November 25, 2026 20:49
somethingwithproof and others added 28 commits November 26, 2026 08:50
…atch 3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…h 3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…hp (batch 3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…h 3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…tch 3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…tch 3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…atch 3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…orm_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…m_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…tch 3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…rm_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…atch 3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
… form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…ch 3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…rm_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…m_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…batch 3: form_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…m_save / automation form_actions / POST-only direct actions)

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…lice fixtures

Follow-up to the batch-3 CSRF-require-POST hardening to green the CI checks
it introduced:

- include/layout.js: add tree_up/tree_down (tree.php) and
  move_page_up/move_page_down (links.php) to the cactiIsPostActionUrl
  transport map so the browser sends these actions as POST, matching the
  new server-side csrf_require_post() guards. Fixes the "JavaScript
  contracts" mutation_transport contract test.

- tests/fixtures/Core/PackageSaveMatrix.php and
  tests/fixtures/UserAdministrationAuditProbe.php: stub a no-op
  csrf_require_post() alongside the other stubbed globals so the
  source-sliced form_save() handlers no longer fatal with an undefined
  function. Fixes the pest unit test, the user-admin integration test,
  the coverage gates, and the PHP native-dependency jobs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Batch 3 added csrf_require_post() to form_save(), the automation
bulk-action execute branches and the in_array action dispatchers, but no
probe ran those lines, so the changed-coverage gates failed. Add
CsrfPostGuardBatch3Probe, which runs each guard from production source in
its own process for GET, tokenless POST and valid POST (and an unguarded
action for the dispatchers), and register it in run_pr_change_tests.sh
and run_request_coverage.sh. A browser spec runs the POST transport map
so its changed entries are covered too.

automation_templates.php ajax_dnd, graph_dnd, tree_dnd and exitonchange,
and automation_graph_rules.php qedit, still wrote on GET through
loadUrl(). Add them to the dispatcher guards and to the POST transport
map so drag and drop, the exit toggle and the query change keep working.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
post-action-transport.spec.js and MutationEndpointPostGuardTest only
check map entries against the server. Nothing caught the opposite
case: an action the dispatcher guard sends to csrf_require_post() that
a page still reaches through loadUrl() or a plain link because the
cactiIsPostActionUrl() map omits it, which answers 405 in the browser.
The dnd and qedit misses fixed earlier in this PR were that kind.

The new test reads every dispatcher guard list and every UI reference
to a guarded action, and reports references that are neither a
cactiPostAction element, a postUrl() or $.post() call, nor listed in
the map. A second case drops qedit and graph_dnd from the map and
expects exactly those two to be reported.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…robe

The user administration audit probe sliced the real csrf_require_post()
out of include/csrf.php and also declared an empty one, so the probe
exited with a redeclaration fatal and every audit integration test
failed. Keep the real guard; the probe already fakes csrf_check() and
sends a POST.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Drag-and-drop reordering in automation SNMP, CDEF, VDEF, color template,
graph and graph template pages, graph input removal, device template
graph and data query add/remove, data input field removal, data source
enable/disable, permission exception removal and the profile logout,
reset and clear actions all wrote on GET and are not in the global
GET denylist. Guard them with csrf_require_post() and send the
loadUrl()-driven ones through the POST transport map. The profile
logout request now posts its token.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
data_input.php form_save() now calls csrf_require_post(). The probe slices form_save() without that function, so the call died before the probe's validation_error shutdown assertion could pass. The probe stands in for a POST request, so it defines a no-op guard like the other sliced save probes.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@github-actions
github-actions Bot force-pushed the fix/csrf-require-post-on-state-change branch from 48a7341 to 894ae1b Compare November 26, 2026 08:50
@sonarqubecloud

Copy link
Copy Markdown

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

bug Undesired behaviour core/config A core feature either system level or config release:1.3 Namespaced Cacti workflow label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant