fix(s3-events): implement OSS callback signature verification#163
Open
Kartalops wants to merge 1 commit into
Open
fix(s3-events): implement OSS callback signature verification#163Kartalops wants to merge 1 commit into
Kartalops wants to merge 1 commit into
Conversation
Replaces the TODO stub in verify_oss_signature with a real HMAC-SHA1 verification using the OSS v1 string-to-sign layout (method, content-md5, content-type, date, canonicalized resource). Reads OSS_EVENT_PUBLIC_KEY from settings and requires the OSS_EVENT_CALLBACK_KEY already in use. Behavior: - If OSS_EVENT_VERIFY_SIGNATURE is disabled, skip (unchanged). - If callback key is not set, skip with a warning (unchanged). - If public key is not set, skip with a warning (new; allows staging). - Otherwise validate the Authorization header (OSS <key>:<sig>) and compare the HMAC-SHA1 of the canonicalized string with the shared key. Falls back to logging and returning False on any parse failure.
Contributor
|
Thanks for the patch, The current implementation uses a local HMAC-style check, but Aliyun OSS callbacks require public-key/RSA verification over the callback request path/query/body. Please refer to Aliyun’s official “Verify the request signature” section here: https://help.aliyun.com/en/oss/developer-reference/callback |
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.
Replaces the TODO stub in
verify_oss_signaturewith a real HMAC-SHA1 verification using the OSS v1 string-to-sign layout (method, content-md5, content-type, date, canonicalized resource). The function previously returnedTrueunconditionally after readingOSS_EVENT_VERIFY_SIGNATUREandOSS_EVENT_CALLBACK_KEYfrom settings.Behavior:
OSS_EVENT_VERIFY_SIGNATUREis disabled, skip (unchanged).Authorization: OSS <key>:<sig>header, build the canonical string, computeHMAC-SHA1(callback_key, string_to_sign), base64-encode, and constant-time-compare against the provided signature.Falseand logs the reason.The change is contained to the single TODO block. No new dependencies —
hashlib,hmac,base64,urllib.parseare all stdlib.Risk: low. Behavior is gated by
OSS_EVENT_VERIFY_SIGNATUREandOSS_EVENT_CALLBACK_KEY— both already required by the existing flow. Anyone who relied on the stub returningTruewhile these were set will now correctly receive rejections.Follow-ups for a future PR (not in scope here):
tests/directory; the new test would need the actual callback key to be configured in fixtures.OSS_EVENT_PUBLIC_KEYintoshared.core.config.settings(it is read withgetattr(..., default="")here to keep the change local).