Skip to content

dynamodb: verify the admin PutItem URL key against the table schema - #1229

Merged
bootjp merged 7 commits into
mainfrom
design/admin-putitem-schema-key-check
Oct 22, 2026
Merged

bootjp merged 7 commits into
mainfrom
design/admin-putitem-schema-key-check

Conversation

@bootjp

@bootjp bootjp commented Sep 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Pass the admin item URL key through the HTTP handler and bridge into the DynamoDB adapter.
  • Validate the URL key against the same fenced table schema used to prepare each write attempt.
  • Reject missing, extra, or value-mismatched primary-key attributes while preserving compatibility with existing schemas that reuse one attribute name for hash and range keys.
  • Revalidate after generation changes so a delete-and-recreate race cannot redirect the write to a row the URL did not identify.

Behavior and risk

A PUT that previously accepted a partial, extra, or mismatched path key now returns the existing admin validation error. Valid single-key and composite-key writes are unchanged. Validation runs inside the existing fenced write-preparation path, so it does not add an unfenced schema read.

Verification

  • go test -race ./adapter ./internal/admin . -run '(AdminPutItem|ValidateAdminPathKey|DynamoItems|DynamoHandler|DynamoTablesBridge)' -count=1 -timeout=30m
  • git diff --check origin/main...HEAD
  • Audited every AdminPutItem caller and implementation with rg.

Closes the item the data-browser design tracked separately: the HTTP
layer checks that every attribute IT received in the URL appears in the
body with the same value, but it has no schema access, so it could not
tell that a composite-key table's URL segment named only the hash key
while the body supplied the range key. The write then landed on a row
the URL never fully identified — the difference between "update the
item this URL names" and "create some other item".

The URL key is now plumbed into AdminPutItem, which loads the table
schema and requires the key to name exactly the primary-key attributes:
missing ones and extras are both rejected. Extras matter too — a key
carrying an attribute the schema does not treat as part of the primary
key means the caller and the table disagree about identity, and
ignoring it would let the mismatch through.

An absent table surfaces as ErrAdminDynamoNotFound from the schema
lookup rather than as a validation error.

Claude-Session: https://claude.ai/code/session_013rNHooj7NF3giihWVba8QE
@bootjp

bootjp commented Sep 10, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@bootjp

bootjp commented Sep 10, 2026

Copy link
Copy Markdown
Owner Author

@claude review

@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9b23f798-8aa7-46dc-a0dd-956298a746e3
📥 Commits

Reviewing files that changed from the base of the PR and between 429f5ee and 9ba9745.

📒 Files selected for processing: 11
  • adapter/dynamodb_admin_items.go
  • adapter/dynamodb_admin_items_test.go
  • adapter/dynamodb_item_write.go
  • adapter/dynamodb_read_fence_test.go
  • docs/design/2026_05_22_implemented_admin_data_browser.md
  • internal/admin/dynamo_handler.go
  • internal/admin/dynamo_handler_test.go
  • internal/admin/dynamo_items_handler.go
  • internal/admin/dynamo_items_handler_test.go
  • main_admin.go
  • main_admin_forward_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

@claude

claude Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Claude finished @bootjp's task in 2m 21s —— View job


Review: dynamodb: verify the admin PutItem URL key against the table schema

Summary

The fix is correctly scoped and the plumbing is consistent end-to-end (HTTP handler → TablesSource interface → bridge → adapter, all four implementations/stubs updated). No blocking issues found.

What looks right

  • assertPathKeyCoversPrimaryKey (adapter/dynamodb_admin_items.go:353-385) correctly handles both directions: missing a required hash/range attribute, and an extra attribute not in the schema's primary key (via the len(pathKey) != len(required) check after the per-name loop). Both failure modes map to ErrAdminDynamoValidation, and an absent table surfaces as ErrAdminDynamoNotFound — matching the documented sentinel contract in the AdminPutItem doc comment.
  • It uses d.loadTableSchema → loadTableSchemaAt(ctx, tableName, snapshotTS(...)), i.e. the same HLC-derived snapshot-read path AdminDescribeTable/AdminGetItem use — consistent with the repo's "never use wall clock for ordering-sensitive reads" rule.
  • handleItemPut (internal/admin/dynamo_items_handler.go:230-251) passes the same key parsed from the URL into both assertItemBodyMatchesPathKey and the new AdminPutItem parameter — no double-parsing or drift risk between the two checks.
  • Test coverage is good: partial composite key, extra-attribute rejection, and missing-table-surfaces-as-not-found are each covered, plus all pre-existing call sites were migrated through the new putItemForTest helper. The PR description calls out that this was revert-checked, which is solid verification.

Minor, non-blocking observations

  1. AdminDeleteItem has a similar-shaped gap that this PR doesn't touch. AdminGetItem validates key shape against the schema via schema.itemKeyFromAttributes (adapter/dynamodb_admin_items.go:249-256), but AdminDeleteItem (line 407) has no equivalent schema check — a delete with a partial or extra key relies entirely on whatever deleteItemWithRetry/translateDynamoAdminError happens to do with it. This is pre-existing and out of scope here (delete doesn't have the "body silently picks the row" problem PutItem has, since there's no body), but worth a follow-up issue if not already tracked.
  2. needsLegacyKeyMigration isn't checked in the new path. The read path (adminLoadReadableSchema) rejects tables pending legacy-key migration; AdminPutItem/assertPathKeyCoversPrimaryKey doesn't check this — but that's unchanged from before this PR (AdminPutItem never had this check), so it's not a regression introduced here.
  3. The error-message ordering in assertPathKeyCoversPrimaryKey means a composite-key table where the URL swaps the range key for some other attribute name (same count, wrong name) reports "missing primary key attribute %q" rather than the count mismatch — a minor message-wording nuance, not a correctness issue, since the sentinel (ErrAdminDynamoValidation) is still correct either way.

Process notes

  • The design-doc-first convention in CLAUDE.md is satisfied here: the fix closes a gap already called out explicitly in the existing *_implemented_* design doc (tracked as "Codex P2 on internal/admin: HTTP handlers for DynamoDB item RPCs (Phase 3a) #813"), and the doc is updated in this PR to record the resolution — a new *_proposed_*.md wasn't needed for a previously-documented, already-scoped follow-up.
  • Couldn't execute go test/golangci-lint myself in this sandbox (network/exec restrictions on fetch and build commands); relying on the test evidence reported in the PR description (go test ./adapter/ ./internal/admin/ . -race, golangci-lint run — both clean) plus manual code reading above.

@bootjp

bootjp commented Sep 13, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T09:06:26.832805Z 9ba9745 Manual request
🔒 Security Review ✅ Completed 2026-10-22T09:07:28.364657Z 9ba9745 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e7c9b584b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread adapter/dynamodb_admin_items.go Resolved
Comment thread adapter/dynamodb_admin_items.go Resolved
Copilot AI balanced review requested due to automatic review settings October 11, 2026 10:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

2 open findings
What changed in this PR

This PR threads the URL path key into AdminPutItem so the DynamoDB adapter can load table schema and validate that the path key names exactly the table’s primary-key attributes (hash + optional range), preventing writes to unintended rows for composite-key tables.

Changes:

  • Extends the TablesSource.AdminPutItem API (handler → bridge → adapter) to accept the URL key map.
  • Adds adapter-side schema-based validation to reject missing/extra primary-key attributes in the path key.
  • Updates/extends DynamoDB admin item tests to cover partial composite keys, extra path-key attributes, and missing-table behavior.
File Description
internal/​admin/​dynamo_handler.go Updates TablesSource interface and documents why the URL key is passed down.
internal/​admin/​dynamo_items_handler.go Passes parsed URL key through to AdminPutItem.
main_admin.go Bridges admin HTTP layer key into adapter call.
adapter/​dynamodb_admin_items.go Adds schema-based path-key vs primary-key validation in adapter AdminPutItem.
adapter/​dynamodb_admin_items_test.go Adds helper + new tests for composite/extra key validation and missing table.
internal/​admin/​dynamo_items_handler_test.go Updates stub signature to include key parameter.
internal/​admin/​dynamo_handler_test.go Updates stub signature to include key parameter.
main_admin_forward_test.go Updates dummy signature to include key parameter.
docs/​design/​2026_05_22_implemented_admin_data_browser.md Updates design doc to mark the previously-tracked gap as fixed.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread adapter/dynamodb_admin_items.go Resolved
Comment thread internal/admin/dynamo_handler.go Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a849faacb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread adapter/dynamodb_admin_items.go Resolved
@bootjp

bootjp commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

Updated this PR to the latest main at 9ba9745c.

  • The merge completed without conflicts.
  • No root inline finding had an original_commit_id matching the prior HEAD; all existing inline findings were stale.
  • Audited every AdminPutItem caller and implementation with rg.
  • Confirmed validation runs inside each fenced write preparation, including generation retries.
  • Confirmed missing, extra, duplicate-name, and value-mismatch cases are covered.
  • Passed: go test -race ./adapter ./internal/admin . -run '(AdminPutItem|ValidateAdminPathKey|DynamoItems|DynamoHandler|DynamoTablesBridge)' -count=1 -timeout=30m
  • Passed: git diff --check origin/main...HEAD
  • Commit signature is verified for bootjp <contact@bootjp.me>.

CI has restarted for the new HEAD.

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 9ba9745cb6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 9ba9745cb6

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@bootjp
bootjp merged commit d38858c into main Oct 22, 2026
11 checks passed
@bootjp
bootjp deleted the design/admin-putitem-schema-key-check branch October 22, 2026 17:25
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.

2 participants