Skip to content

CLDSRV-1021: Compare s3:VersionId with the copy source version ID as sent - #6332

Open
tcarmet wants to merge 2 commits into
development/9.3from
bugfix/CLDSRV-1021-copy-source-version-id
Open

tcarmet wants to merge 2 commits into
development/9.3from
bugfix/CLDSRV-1021-copy-source-version-id

Conversation

@tcarmet

@tcarmet tcarmet commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

A policy condition on s3:VersionId was compared with the copy source's internal version ID instead of the version ID the client sent. So a Deny on a specific version blocked a GetObject of that version but not a copy of it, in both bucket and identity policies. The copy source's version ID is now evaluated as sent, like for a direct GetObject. A repeated versionId in the copy source is rejected, so it never reaches policy evaluation as a list. Version IDs that decode to the same version under different spellings are still not normalized; that's tracked in CLDSRV-1038 and affects GetObject the same way.

Stacked on #6324.

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.36%. Comparing base (4a58308) to head (dd591e5).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

Files with missing lines Coverage Δ
lib/api/api.js 95.12% <100.00%> (+0.71%) ⬆️
lib/api/apiUtils/authorization/permissionChecks.js 97.32% <100.00%> (+0.01%) ⬆️
...i/apiUtils/authorization/prepareRequestContexts.js 95.62% <ø> (ø)
lib/api/apiUtils/object/parseCopySource.js 96.00% <100.00%> (+0.76%) ⬆️
lib/api/objectCopy.js 91.73% <ø> (ø)
lib/api/objectPutCopyPart.js 87.57% <ø> (+0.59%) ⬆️
lib/metadata/metadataUtils.js 94.73% <ø> (ø)

... and 2 files with indirect coverage changes

@@               Coverage Diff                @@
##           development/9.3    #6332   +/-   ##
================================================
  Coverage            85.35%   85.36%           
================================================
  Files                  207      207           
  Lines                13473    13480    +7     
================================================
+ Hits                 11500    11507    +7     
  Misses                1973     1973           
Flag Coverage Δ
file-ft-tests 68.27% <81.81%> (-0.02%) ⬇️
file-ft-tests-null-compat 68.79% <81.81%> (+<0.01%) ⬆️
kmip-ft-tests 28.35% <72.72%> (+0.01%) ⬆️
mongo-v0-ft-tests 69.47% <81.81%> (-0.03%) ⬇️
mongo-v1-ft-tests 69.49% <81.81%> (+<0.01%) ⬆️
multiple-backend 36.83% <18.18%> (-0.02%) ⬇️
s3c-ft-tests-v0 64.07% <90.90%> (+0.02%) ⬆️
s3c-ft-tests-v0-null-compat 64.13% <90.90%> (+0.02%) ⬆️
s3c-ft-tests-v1 64.05% <90.90%> (-0.02%) ⬇️
sur-tests 37.01% <72.72%> (+0.11%) ⬆️
sur-tests-inflights 37.73% <72.72%> (-0.02%) ⬇️
unit 71.83% <100.00%> (+0.04%) ⬆️
utapi-v2-tests 34.63% <72.72%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@leif-scality leif-scality 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.

A Deny on s3:VersionId now blocks copying that version, in bucket and IAM policies, and a repeated versionId in the copy source is rejected. I found no regressions. The new functional test fails without the fix and passes with it, and the stack's functional tests pass 20/20 against Vault 7.89.0. The other-spelling bypass stays in CLDSRV-1038, as the description says.

@tcarmet
tcarmet requested a review from a team October 29, 2026 21:48
@tcarmet
tcarmet force-pushed the bugfix/CLDSRV-1021-copy-source-version-id branch from 57d9720 to 5c5a75b Compare October 30, 2026 16:48
@tcarmet
tcarmet force-pushed the bugfix/CLDSRV-1021-copy-source-version-id branch from 5c5a75b to 7a9b5bc Compare October 30, 2026 22:58
@tcarmet
tcarmet force-pushed the bugfix/CLDSRV-1021-copy-source-version-id branch from 7a9b5bc to 647a09f Compare November 3, 2026 17:35
…sent

- Use the copy source version ID as sent by the client, for both the bucket
  policy and the authorization request, instead of the internal version ID
- Return InvalidArgument when the copy source versionId is repeated, so an
  array never reaches the bucket policy conditions
@tcarmet
tcarmet force-pushed the bugfix/CLDSRV-1021-copy-source-version-id branch from 647a09f to dd591e5 Compare November 3, 2026 19:46
Base automatically changed from bugfix/CLDSRV-1021-copy-source-bucket-policy to development/9.3 November 3, 2026 19:57
@bert-e

bert-e commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Hello tcarmet,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Available options
name description privileged authored
/after_pull_request Wait for the given pull request id to be merged before continuing with the current one.
/bypass_author_approval Bypass the pull request author's approval ⭐
/bypass_build_status Bypass the build and test status ⭐
/bypass_commit_size Bypass the check on the size of the changeset TBA ⭐
/bypass_incompatible_branch Bypass the check on the source branch prefix ⭐
/bypass_jira_check Bypass the Jira issue check ⭐
/bypass_peer_approval Bypass the pull request peers' approval ⭐
/bypass_leader_approval Bypass the pull request leaders' approval ⭐
/bypass_source_branch_lineage Bypass the cross-branch contamination check ⭐
/approve Instruct Bert-E that the author has approved the pull request. ✍️
/create_pull_requests Allow the creation of integration pull requests.
/create_integration_branches Allow the creation of integration branches.
/no_octopus Prevent Wall-E from doing any octopus merge and use multiple consecutive merge instead
/unanimity Change review acceptance criteria from one reviewer at least to all reviewers
/wait Instruct Bert-E not to run until further notice.
Available commands
name description privileged
/help Print Bert-E's manual in the pull request.
/status Print Bert-E's current status in the pull request.
/clear Remove all comments from Bert-E from the history TBA
/retry Re-start a fresh build TBA
/build Re-start a fresh build TBA
/force_reset Delete integration branches & pull requests, and restart merge process from the beginning.
/reset Try to remove integration branches unless there are commits on them which do not appear on the source branch.

Status report is not available.

@bert-e

bert-e commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Request integration branches

Waiting for integration branch creation to be requested by the user.

To request integration branches, please comment on this pull request with the following command:

/create_integration_branches

Alternatively, the /approve and /create_pull_requests commands will automatically
create the integration branches.

const copySourceVersionId = sourceQuery?.versionId;

return { sourceBucket, sourceObject, sourceVersionId };
return { sourceBucket, sourceObject, sourceVersionId, copySourceVersionId };

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.

I was a bit bothered by the fact that we still return the decoded version ID where only the encoded one is really useful. I asked Claude if we could get rid of it, and it seems that it's also more in line with the other API calls, so if you feel like it, I'd suggest to simply return the encoded version ID as sourceVersionId for consistency and simplicity, and defer the actual validation of the version ID to the lower level.

Here's the full response from Claude 🤖 , in case it helps implementing the changes:

Code changes

  • parseCopySource would return only { sourceBucket, sourceObject, sourceVersionId, parsingError }, with sourceVersionId now the raw string. Keep the repeated-versionId (array) check there: it has to run before authorization, because that's what keeps an array out of the policy conditions.
  • api.js passes the raw ID to both prepareRequestContexts and the handler. The request.copySourceVersionId = ... assignment goes away.
  • objectCopy and objectPutCopyPart decode at the top with decodeVID and return the InvalidArgument error through the callback, as keyLengthError already does in objectCopy. They use the raw ID for policyTarget.versionId and the decoded one for valGetParams.versionId, the NoSuchVersion and delete-marker checks, and x-amz-copy-source-version-id. That header is currently re-encoded from the decoded ID (objectCopy.js:798), so it could take the raw value directly. Either way, normalize '' to undefined the way decodeVersionId does.

Behavior changes

  1. Errors come in a different order. Today, a malformed copy source version ID returns InvalidArgument from api.js before any authorization. After the change, authorization runs first:
    • A requester without permission gets AccessDenied instead of InvalidArgument. GetObject with a malformed ?versionId= already behaves this way, and checking auth first is the safer order.
    • An authorized requester still gets InvalidArgument, now from the handler. The existing functional test at tests/functional/aws-node-sdk/test/versioning/objectPutCopyPart.js:124 uses the bucket owner, so it should still pass. Verify this by running it.
  2. Vault would see a malformed ID. The objectGetVersion request context could carry a garbage version ID. The context treats the value as opaque, and other routes already send unvalidated values to Vault, so this is harmless.
  3. versionId= (empty string) behaves as it does today. Authorization checks truthiness, so it stays objectGet, and the handler's decode gives undefined as before.
  4. 'null' is unchanged. decodeVID('null') returns 'null', so raw and decoded are the same.
  5. Metrics and logging change slightly. The early return in api.js (process.nextTick(callback, parsingError)) skips the handler. The error would now go through the handler's normal error path. That probably doesn't matter, but malformed version IDs may start showing up in per-API error metrics where they didn't before.

Tests to update

  • tests/unit/api/objectCopy.js calls the handler with decoded IDs at lines 979, 989 and 1120 (versioning.VersionID.decode(...)). Those calls should pass the encoded ID. The CLDSRV-1021 tests also get simpler, since they no longer need to keep request.copySourceVersionId and the decoded argument in sync.
  • The calls passing undefined or 'null', including the ones in tests/multipleBackend/, need no change.
  • Add a unit test for a malformed source version ID reaching the handler, since the handler now owns that check.

Overall it's a modest simplification. Copy becomes structurally the same as the other routes: authorization sees the raw value, and the handler decodes where it needs the internal ID. Before doing it, decide whether you're fine with the AccessDenied-before-InvalidArgument change. I'd keep it, since it matches GetObject.

This branch has not been deployed

No deployments
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.

4 participants