#20657: Security: add length validation to browser evaluate function
size: XS
Cluster:
SSRF Protection Enhancements
## Summary
- Add a 100KB max length check on evaluate function bodies in `pw-tools-core.interactions.ts`
- The browser sandbox is the primary security boundary for `evaluateViaPlaywright`; this is defense-in-depth to limit oversized payloads
- Clear security comment explaining the architecture
## Test plan
- [ ] Run browser-related tests
- [ ] Verify normal evaluate calls (typically <1KB) work as before
- [ ] Verify oversized payloads (>100KB) are rejected with a clear error message
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Added a 100KB max length check on evaluate function bodies in `evaluateViaPlaywright` to limit oversized payloads as defense-in-depth security measure. The implementation correctly validates before executing the function and provides a clear error message.
**Key changes:**
- Added `MAX_EVALUATE_FN_LENGTH` constant (100,000 bytes)
- Length check with descriptive error message showing actual vs max size
- Clear security comment explaining the defense-in-depth rationale
**Issue found:**
- `waitForViaPlaywright` also accepts function strings via `opts.fn` parameter on line 446 and passes them to `page.waitForFunction` without the same length validation, which is an inconsistency in the security boundary
<h3>Confidence Score: 4/5</h3>
- Safe to merge with one inconsistency to address: `waitForViaPlaywright` lacks the same length validation
- The implementation is solid - correct validation placement, clear error messages, and good security comments. Score of 4 (not 5) due to incomplete coverage: `waitForViaPlaywright` on line 446 also accepts function strings but doesn't have the same length check, creating an inconsistency in the security boundary
- Pay attention to `waitForViaPlaywright` function (line 446) which needs the same length validation for consistency
<sub>Last reviewed commit: 7f52b4f</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#8818: fix(browser): block unsafe code patterns in browser evaluate
by yubrew · 2026-02-04
81.7%
#8305: fix(browser): add SSRF protection to browser navigation
by yubrew · 2026-02-03
74.5%
#14197: fix(security): harden browser API auth, token comparisons, and hook...
by leecarollyn-gif · 2026-02-11
71.4%
#8124: fix(browser): add path validation for file upload and download
by yubrew · 2026-02-03
70.9%
#8718: fix: sanitize download filenames to prevent path traversal (CWE-22)
by DevZenPro · 2026-02-04
70.1%
#8517: Browser: sandbox download/trace paths
by coygeek · 2026-02-04
69.8%
#19823: fix(browser): stability improvements for headless Chrome
by Milofax · 2026-02-18
69.1%
#21136: fix(security): harden agent autonomy controls
by novalis133 · 2026-02-19
68.7%
#15757: feat(security): add hardening gap audit checks
by saurabhsh5 · 2026-02-13
68.6%
#21119: Security/Browser: fail closed when control server has no auth
by bmendonca3 · 2026-02-19
68.6%