Repository navigation
fix(browser): make the automation CSP apply, and test the Chrome paths - #183
Merged
Merged
Conversation
The document CSP that keeps popups, workers and stray connections out of an agent-driven page never ran: Chrome paused documents only at the request stage, and only applies the sandbox part of a CSP header edited with continueResponse. Documents are now paused at the response stage and fulfilled with the policy. Screenshots are named by their real format (JPEG was written to .png files). Adds Chrome fixtures for control errors, the CSP and unloadable pages, and tests for the IMAP expunge warnings.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
A security layer that never ran
While writing a fixture for the CSP that the automation session adds to every page, the test showed the policy was not applied at all. Debug logging confirmed it: documents were paused only at the request stage, never at the response stage where the policy is added, so that code path (about 5 statements, flagged as uncovered) had never executed.
Two Chrome details were behind it, both fixed in
restrictDocument/checkRequest:ContinueRequestsetsInterceptResponse.sandboxpart of a CSP header edited withFetch.continueResponse.worker-srcandconnect-srcare ignored. Fulfilling the response with its own body and the new header makes the whole policy count. Redirects continue untouched, and a response with nothing to read falls back to the header edit.What this means: the request-level destination checks (the main control) were always working. This was the extra layer meant to stop popups, workers and stray channels the interceptor can't see. Popups opened with
window.openwere not blocked before; now they are, and a page-started worker is refused.TestInjectedCSPAppliesruns a real page against it. All existing Chrome tests and the MCP demo workflow pass with the policy active.Also in this PR
.pngfiles. Nothing depended on the name (the screenshot route sniffs the content type).\Deleted, and the test shows the stray message really is removed. Another case checks it stays quiet otherwise.docs/code-patterns.mdrecords the Chrome quirk so it isn't reintroduced.Verified: full suite, race tests, lint, and
GOOS=windows go vet. Statement coverage 90.9% on this branch alone.