Skip to content

fix(#267): forward all presigned POST fields to S3 in upload_body_image - #268

Open
sendashuichiro wants to merge 1 commit into
drillan:mainfrom
sendashuichiro:fix/267-body-image-s3-presigned-fields
Open

sendashuichiro wants to merge 1 commit into
drillan:mainfrom
sendashuichiro:fix/267-body-image-s3-presigned-fields

Conversation

@sendashuichiro

Copy link
Copy Markdown

概要

closes #267

upload_body_image のS3プリサインドPOSTで、固定8キーの決め打ちにより x-amz-security-token フィールドが送信から漏れ、S3が常に 403 AccessDenied を返していた問題を修正します。

変更内容

src/note_mcp/api/images.pyupload_body_image 内、S3へのmultipartフォームデータ構築部分で、固定キーのみを拾う実装から、presigned_post レスポンスの post フィールドを全て動的に転送する実装に変更しました。

-    # Order matters for S3 - policy fields first, then file
+    # Order matters for S3 - send all fields returned by presigned_post as-is
+    # (note.com may include additional fields like x-amz-security-token when
+    # using temporary STS credentials; forwarding everything avoids AccessDenied)
     files_data: dict[str, tuple[None, str] | tuple[str, bytes, str]] = {
-        "key": (None, str(post_fields["key"])),
-        "acl": (None, str(post_fields.get("acl", ""))),
-        "Expires": (None, str(post_fields.get("Expires", ""))),
-        "policy": (None, str(post_fields["policy"])),
-        "x-amz-credential": (None, str(post_fields["x-amz-credential"])),
-        "x-amz-algorithm": (None, str(post_fields["x-amz-algorithm"])),
-        "x-amz-date": (None, str(post_fields["x-amz-date"])),
-        "x-amz-signature": (None, str(post_fields["x-amz-signature"])),
+        field_name: (None, str(field_value)) for field_name, field_value in post_fields.items()
     }

必須フィールドの事前検証(required_s3_fields)は変更していません。

動作確認

実環境(note.com本番API・実アカウント)で note_upload_body_image を呼び出し、修正前は毎回 403 で失敗すること、修正後は画像アップロードが成功しS3アセットURLが返ることを確認しました。

修正前: エラー [api_error]: Failed to upload image to S3: 403
修正後: 本文用画像をアップロードしました。URL: https://assets.st-note.com/img/...

調査・検証について

原因調査、実装、実環境での動作確認はClaude Code(AI)が実施しました。人間によるコードレビューをお願いします。

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

…ody_image

The S3 presigned POST response includes an x-amz-security-token field
(required when note.com issues temporary STS credentials), but the
hardcoded field list only forwarded 8 fixed keys, silently dropping it.
This caused every upload_body_image call to fail with 403 AccessDenied.

Forward all fields returned by presigned_post instead of a fixed
allowlist, so future field additions on note.com's side don't break
uploads again.

Verified against the real note.com API: image upload now succeeds and
returns a valid asset URL.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015zETzrAsuT6sm8YRdDdx9C
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: upload_body_imageのS3アップロードがx-amz-security-token欠落で403になる

1 participant