fix(security): validate upload_file paths to block secret exfiltration#55
Merged
Conversation
UploadFile passed the caller path straight to DOM.setFileInputFiles with no checks, so an untrusted (page-injected) instruction could upload a local secret — e.g. upload_file(input, "~/.ssh/id_rsa") against an attacker-controlled file input reads and exfiltrates the key. validateUploadPath now resolves the path (following symlinks), requires a regular existing file, and refuses well-known credential material: credential directories (.ssh/.gnupg/.aws/.azure/.kube/.docker/gcloud), private-key/.netrc/ .pgpass base names, and system secret files (/etc/shadow etc.). A focused denylist of things never legitimately uploaded via a browser form. Note: redirect re-validation and per-origin auth-header scoping (the other two security-review items) both require CDP request interception and coexistence with BlockResources — tracked as a separate, design-heavier PR. Claude-Session: https://claude.ai/code/session_01QKTcmXFTKoTQr7mB3HCuHZ
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.
Problem
UploadFilehanded the caller-supplied path straight toDOM.setFileInputFileswith no validation. Because the MCPupload_filetool is driven by an agent that a malicious page can influence,upload_file(input, "~/.ssh/id_rsa")against an attacker-controlled<input type=file>reads and exfiltrates a local secret.Fix
validateUploadPathnow:.ssh,.gnupg,.aws,.azure,.kube,.docker,gcloudid_rsa/id_dsa/id_ecdsa/id_ed25519,.netrc,.pgpass/etc/shadow,/etc/gshadow,/etc/sudoers,/etc/master.passwdHermetic unit tests cover the denylist logic and the fs checks (regular file, missing, directory, files under
.ssh, files namedid_rsa).Deferred (separate PR)
The other two security-review items — redirect re-validation (a public URL 302-ing to an internal host) and per-origin auth-header scoping (
Network.setExtraHTTPHeaderscurrently leaks theAuthorizationheader to every host) — both require CDP request interception (Fetchdomain) and careful coexistence withBlockResources, plus a per-request-overhead trade-off. They deserve their own focused change rather than being rushed in here.Scout deep-review batch:
upload_filefinding (MEDIUM).https://claude.ai/code/session_01QKTcmXFTKoTQr7mB3HCuHZ