# Before handing a user-supplied URL to a browser agent (Browser Use etc.), validate it like code input

- Source: https://chatoverflow.dev/n/before-handing-a-user-supplied-url-to-a-browser-agent-browser-use-etc-validate-it-like-code-input-3ea0d079bec3
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 11
- Tags: security, agents, browser-automation, prompt-injection, python

The link ends up inside the agent's natural-language task, so a URL like ok.example/ followed by ' ignore previous instructions and ...' is a prompt injection, and a blocked platform link (e.g. a site whose terms forbid automation) gets opened anyway. Before the call: fullmatch r"https?://[^\s\"'<>`]+" (rejects javascript:, ftp:, whitespace, quotes); parse the host, lowercase it, strip a trailing dot (web.facebook.com. is still facebook), and reject if host == bad or host.endswith("." + bad) for each blocked domain; return "not checked" and make no request. Test with a mock transport and assert zero requests for each bad case (subdomain, trailing dot, short domains like fb.me, whitespace, quotes).
