fix(file_transfer): strip query params from pre-signed URLs before logging (CWE-532)#14
Closed
sebastiondev wants to merge 1 commit into
Closed
Conversation
FileTransfer.upload() and download() logged the full pre-signed OSS URLs including query-string parameters that contain authentication tokens (OSSAccessKeyId, Signature, Expires). Anyone with access to logs could use these bearer-token URLs to upload/download files without credentials. Add a _sanitize_url() helper that strips query and fragment from URLs before they are interpolated into log messages. The URL path is still logged for debugging purposes.
|
Closing this to reduce the open-PR pile-up — we have multiple outstanding security contributions to this repo and that volume is not fair on your review queue. Keeping #11 (fix: reject symlinks in extension upload to prevent arbitrary file exfiltration ) as the primary one to focus attention on. Happy to revisit this finding separately later if it is still relevant. Apologies for the noise. |
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.
Summary
Pre-signed OSS URLs are logged in plaintext at INFO level by
FileTransfer.upload()andFileTransfer.download()inpython/agb/modules/file_transfer.py. These URLs contain bearer-token query parameters (Signature,OSSAccessKeyId,Expires) — anyone who reads the log line within the URL's expiry window can replay it to read or write the corresponding object, no API key required.python/agb/modules/file_transfer.pyFileTransfer.upload()(line ~225),FileTransfer.download()(line ~486)Data flow
agb.context.get_file_upload_url(...)/get_file_download_url(...)returns a pre-signed OSS URL whose query string carries the OSS signature.logger.info(f"... URL: {upload_url}")/logger.info(f"... URL: {download_url}").Fix
Add a small
_sanitize_url()helper that usesurllib.parse.urlsplitto strip the query string and fragment, and apply it at the two log sites:The host and path are still logged (useful for debugging which bucket/object was touched); only the signing parameters are removed. The URL value used for the actual HTTP PUT/GET is unchanged — only the logged representation is sanitized.
I checked
python/agb/modules/context.pyas well, since it also handles pre-signed URLs; it never logs the URL string (onlycontext_id,file_path,request_id), so no changes are needed there. These two log statements infile_transfer.pyare the only places URLs were emitted in this module.Tests
Added
python/tests/unit/test_cwe532_presigned_url_leak.pywith two cases:test_upload_does_not_log_presigned_url_query_params— exercisesupload()with a fake pre-signed URL containingOSSAccessKeyId,Expires,Signature, captures loguru output, asserts none of those tokens appear.test_download_does_not_log_presigned_url_query_params— same fordownload().Both tests fail against the current code on
master(the URL with all query params is logged verbatim) and pass with the fix applied. The existing file_transfer test suite continues to pass — the change is confined to log formatting.Security analysis
Why this is exploitable in practice:
Expireswindow (typically minutes to hours). During that window, possession of the URL = possession of the object.Preconditions for exploitation:
Adversarial review
Before submitting I tried to disprove this. The main "is it really a vuln?" angles:
Signature,OSSAccessKeyId,Expiresare present in the query string and are exactly the bearer material OSS validates.The preconditions (log read access) do not already grant equivalent OSS object access, so the fix provides a real reduction in blast radius.
cc @lewiswigmore