Repository navigation
fix(data-machine): gate web_fetch on edit_posts and make action capabilities filterable - #3996
Merged
Merged
Conversation
…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
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.
Fixes #3993
Summary
PermissionHelper::CAPABILITY_MAP:web_fetchnow maps toedit_postsinstead ofpublish_posts.datamachine/web-fetchreads 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 inWebFetchAbilitiesare unchanged.web_fetchstays inIMPLIED_BY_MANAGEMENT, and that docblock is updated (the old text wrongly said the tool already required publish level).datamachine_action_capabilityfilter (apply_filters( 'datamachine_action_capability', $mapped, $action )), documented with a docblock. It lives in a new privateresolve_action_capability(), which is now the only placeCAPABILITY_MAPis read. Bothuser_can()andagent_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.web_fetchtool (Engine/AI/Tools/Global/WebFetch.php) has no publish-level check. It is registered withaccess_level => 'author', which resolves to theuse_toolsaction (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:edit_posts, lackspublish_posts) passesPermissionHelper::can( 'web_fetch' )anddatamachine/web-fetchcheck_permissions().web_fetch:edit_postsis allowed,readalone is denied.web_fetchis remapped topublish_posts) and loosen one (subscriber allowed when it is remapped toread). It applies in agent-token context, it receives the built-in mapping, and an empty return denies the action.Verification
php -lon 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.phpfails 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.AI-generated (Claude, Pi subagent). Finalized outside Homeboy by operator authorization: the lab runner was unavailable.