T09 · Insecure Skill Coding Practices
- Location
scripts/shipment_tracker.py:251- Finding
Arbitrary Python Code Injection Through Generated Browser-Use Command
- Content
View full analysis
Vulnerability Details
File Location:
scripts/shipment_tracker.py, lines 143–145 and 251–264
Vulnerability Type: Command generation using untrusted shipment data without escaping
Risk Level: HighThe application reads a user-controlled tracking link from a Markdown shipment table and later embeds that value directly into executable Python source presented as a browser-use fallback command.
Relevant source of untrusted input at lines 143–145:
python # Extract URL from markdown link syntax [text](url) link_match = re.search(r"\[.*?\]\((.*?)\)", link_raw) link = link_match.group(1) if link_match else link_rawThe untrusted link is assigned to
tracking_urland interpolated into generated Python code at lines 251–264:python result["browser_use_command"] = f"""python3 -c " import asyncio from browser_use import Agent, Browser, ChatBrowserUse async def main(): browser = Browser(use_cloud=True) llm = ChatBrowserUse() agent = Agent( task='Go to {result["tracking_url"]} and extract the current tracking status, delivery date, and location', llm=llm, browser=browser ) result = await agent.run(max_steps=10) print('TRACKING:', result) asyncio.run(main()) \""""Technical Analysis
shipment.linkoriginates from theLinkcolumn of the supplied Markdown file and is not validated as a URL or escaped for use in Python source. During a browser-use fallback,result["tracking_url"]is inserted inside a single-quoted Python string in apython3 -ccommand.An attacker-controlled link containing a single quote and a Python expression can terminate or alter the intended string expression. For example, a raw
Linkcell shaped like the following can cause an operating-system command to execute when the generated command is run:text https://example.invalid/'+__import__('os').system('id')+'This changes the generated
task...[truncated 2233 chars]- Remediation
View remediation
Remediation Suggestions
-
Do not generate executable Python source from shipment data. Replace the inline
python3 -coutput with a fixed, reviewed helper script that accepts the tracking URL as a data argument. -
Pass values through argument boundaries. If a command must be displayed, pass the URL through
sys.argvrather than interpolating it into Python code. Generate any shell representation withshlex.quote, while treating shell quoting as defense in depth rather than the primary fix. -
Prefer structured output. Emit the fallback request as JSON containing separate fields such as
tracking_urlandtask, and have trusted application code invoke the browser-use API without evaluating generated source. -
Validate tracking URLs before use. Parse links with
urllib.parse.urlsplitand require:- The
httpsscheme. - No embedded credentials.
- A hostname from an explicit carrier-domain allowlist.
- Rejection of control characters, quotes, and malformed URLs.
- The
-
Do not trust a supplied link when a carrier is known. Generate the URL from the carrier's fixed template and a strictly validated tracking number instead of honoring an arbitrary
Linkfield. -
Add regression tests. Include shipment links containing single quotes, double quotes, backslashes, newlines, Python expressions, shell metacharacters, and malformed Markdown. Verify that none are incorporated into executable source and that invalid or non-carrier URLs are rejected.
-
