Skip to content

fix(data-machine): gate web_fetch on edit_posts and make action capabilities filterable - #3996

Merged
chubes4 merged 1 commit into
mainfrom
fix/issue-3993-web-fetch-cap
Nov 18, 2026
Merged

chubes4 merged 1 commit into
mainfrom
fix/issue-3993-web-fetch-cap

Conversation

@chubes4

@chubes4 chubes4 commented Nov 18, 2026

Copy link
Copy Markdown
Member

Fixes #3993

Summary

  • PermissionHelper::CAPABILITY_MAP: web_fetch now maps to edit_posts instead of publish_posts. datamachine/web-fetch reads a public http(s) page as text, refuses internal/private addresses, and persists nothing, so anyone who can draft content can use it to research. The SSRF protections in WebFetchAbilities are unchanged. web_fetch stays in IMPLIED_BY_MANAGEMENT, and that docblock is updated (the old text wrongly said the tool already required publish level).
  • New datamachine_action_capability filter (apply_filters( 'datamachine_action_capability', $mapped, $action )), documented with a docblock. It lives in a new private resolve_action_capability(), which is now the only place CAPABILITY_MAP is read. Both user_can() and agent_can() call it, so user sessions, pre-authenticated contexts and agent tokens all see the same filtered capability. Agent tokens are still limited by their capability ceiling. If the filter returns a non-string or empty value, the action is denied.
  • The web_fetch tool (Engine/AI/Tools/Global/WebFetch.php) has no publish-level check. It is registered with access_level => 'author', which resolves to the use_tools action (datamachine_use_tools). I left it alone: linking it to the ability would change who can use it inside pipelines and agents, which is outside this issue.

Tests

New tests/Unit/Abilities/WebFetchPermissionTest.php:

  • A contributor (has edit_posts, lacks publish_posts) passes PermissionHelper::can( 'web_fetch' ) and datamachine/web-fetch check_permissions().
  • A subscriber and a logged-out visitor are denied.
  • An agent token ceiling still limits web_fetch: edit_posts is allowed, read alone is denied.
  • The filter can tighten an action (contributor denied when web_fetch is remapped to publish_posts) and loosen one (subscriber allowed when it is remapped to read). It applies in agent-token context, it receives the built-in mapping, and an empty return denies the action.

Verification

  • php -l on both changed files: clean.
  • homeboy review lint data-machine --placement local --changed-since origin/main: phpcs, eslint and phpstan (level 7) all passed with 0 findings.
  • homeboy review test data-machine --placement local --skip-lint -- --filter 'WebFetchPermissionTest|PermissionHelperTest|UploadMediaPermissionTest' (WP Codebox, SQLite config): PHPUnit 47/47 passed. The run still exited 1 because of one standalone smoke in the same run, which comes from the environment and is unrelated to this change: run directly, tests/phpunit-file-isolation-smoke.php fails with "PHPUnit/PHPCS must start and report its version" because there are no local binaries. tests/web-fetch-ability-smoke.php (SSRF/redirect coverage) passes.
  • The full PHPUnit suite was not run locally. CI's MySQL run is the authority for that.

AI-generated (Claude, Pi subagent). Finalized outside Homeboy by operator authorization: the lab runner was unavailable.

…ilities filterable

datamachine/web-fetch is a read-only, SSRF-protected public page fetch that
persists nothing, so map the web_fetch action to edit_posts instead of
publish_posts. Contributors and submit-for-review roles can now research a
public page they can already draft about.

Route every CAPABILITY_MAP read through resolve_action_capability(), which
applies the new datamachine_action_capability filter, so user sessions,
pre-authenticated contexts and agent tokens share one filterable mapping.

Fixes #3993
@chubes4
chubes4 merged commit dc25b98 into main Nov 18, 2026
38 checks passed
@chubes4
chubes4 deleted the fix/issue-3993-web-fetch-cap branch November 18, 2026 04:53
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.

web-fetch requires publish_posts for a read-only public fetch; make action capabilities filterable

1 participant