Agent Wranglers

Requests and files Required

Keep file paths inside their folder

Never build a file path from user input without proving the result stays inside the allowed folder.

How to do it

Prefer IDs that map to files on the server. If you must use a name, resolve the full path and check that it starts with the allowed folder. Reject names with .., slashes or null bytes.

Example

/download?file=../../etc/hostname
/download?file=..%2f..%2fetc%2fhostname
/download?file=....//....//etc/hostname
const full = path.resolve(UPLOADS, name);
if (!full.startsWith(UPLOADS + path.sep)) return res.status(404).end();
# Python 3.9 or later
full = (UPLOADS / name).resolve()
if not full.is_relative_to(UPLOADS.resolve()):
    abort(404)
// Go 1.24 or later: an os.Root refuses paths that leave the folder
root, err := os.OpenRoot(uploads)
if err != nil { return err }
file, err := root.Open(name)

How to check

The agent asks for files outside the folder, in plain and encoded forms. Every request fails.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers security testing playbook: https://agentwranglers.se/playbook/adversarial-testing/requests-and-files/block-path-traversal.