Skip to content

CLDSRV-1099: Refuse malformed grant headers instead of crashing - #6422

Open
nicolas2bert wants to merge 1 commit into
development/9.4from
bugfix/CLDSRV-1099-validate-grant-headers
Open

nicolas2bert wants to merge 1 commit into
development/9.4from
bugfix/CLDSRV-1099-validate-grant-headers

Conversation

@nicolas2bert

@nicolas2bert nicolas2bert commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Issue: CLDSRV-1099

problem

If you send a grant header that isn't a list of type=identifier pairs, like x-amz-grant-read: x, the server crashes. An empty grant header crashes it too. On PutBucketAcl you don't even need credentials or a bucket. On PutObject, CreateMultipartUpload and CopyObject you need write access on one bucket.

reproduction

  1. Send an anonymous PUT /no-such-bucket?acl with x-amz-grant-read: x. The worker exits with Callback was already called.
  2. Send a PutObject with an empty x-amz-grant-read. The worker exits with Cannot read properties of undefined (reading 'trim').
  3. Send a CreateMultipartUpload with x-amz-grant-read: x. Same crash.
  4. Send a CopyObject with x-amz-grant-read: x. Same crash.
  5. To compare: a PutObject with a valid x-amz-grant-read: uri=http://acs.amazonaws.com/groups/global/AllUsers returns 200, and the server stays up.

expected

We want the same answers as AWS, and the server stays up:

  • x-amz-grant-read: x on PutBucketAcl, PutObject, PutObjectAcl, CopyObject or CreateMultipartUpload: 400 InvalidArgument.
  • PutObject with an empty x-amz-grant-read: 200. The empty header is just ignored.
  • PutObjectAcl with only an empty x-amz-grant-read: 400.

AWS

We checked each case on AWS S3 on 2026-12-04, and that's what it returns. AWS also takes a quoted value, like uri="http://acs.amazonaws.com/groups/global/AllUsers", and returns 200. CloudServer returns 400 on it today.

@bert-e

bert-e commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Hello nicolas2bert,

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 Dec 4, 2026

Copy link
Copy Markdown
Contributor

Incorrect fix version

The Fix Version/s in issue CLDSRV-1099 contains:

  • None

Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:

  • 9.4.24

  • 9.5.14

  • 9.6.4

  • 9.7.0

Please check the Fix Version/s of CLDSRV-1099, or the target
branch of this pull request.

Comment thread tests/unit/api/aclGrantHeaders.js Outdated
[{ userIDType: 'uri', identifier: constants.publicId, grantType: 'READ' }],
],
].forEach(([name, value, expected]) => {
it(`parseGrant skips a grant with ${name} instead of throwing`, () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test names in this repo should start with should. That applies to every it() in this file.

Suggested change
it(`parseGrant skips a grant with ${name} instead of throwing`, () => {
it(`should skip a grant with ${name} in parseGrant instead of throwing`, () => {

it('parseAclFromHeaders refuses an invalid canonical id', done => {
const params = { headers: { 'x-amz-grant-read': 'id=123' }, resourceType: 'object', acl: {}, log };
acl.parseAclFromHeaders(params, err => {
assert(err && err.is.InvalidArgument, `expected InvalidArgument, got ${err}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Compare the error message instead of using err.is.*, so a failure shows the actual error name. The same pattern appears throughout this file.

Suggested change
assert(err && err.is.InvalidArgument, `expected InvalidArgument, got ${err}`);
assert.strictEqual(err?.message, 'InvalidArgument');

@codecov

codecov Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.90%. Comparing base (28b50da) to head (fb04f04).
⚠️ Report is 13 commits behind head on development/9.4.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
lib/metadata/acl.js 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

Files with missing lines Coverage Δ
lib/api/initiateMultipartUpload.js 91.80% <100.00%> (+0.23%) ⬆️
lib/api/objectCopy.js 91.34% <100.00%> (+0.11%) ⬆️
lib/utilities/aclUtils.js 84.52% <100.00%> (+0.47%) ⬆️
lib/metadata/acl.js 97.61% <50.00%> (-1.17%) ⬇️

... and 4 files with indirect coverage changes

@@                 Coverage Diff                 @@
##           development/9.4    #6422      +/-   ##
===================================================
+ Coverage            86.84%   86.90%   +0.05%     
===================================================
  Files                  214      214              
  Lines                14756    14773      +17     
===================================================
+ Hits                 12815    12838      +23     
+ Misses                1941     1935       -6     
Flag Coverage Δ
checksums-disabled-tests 35.21% <20.00%> (-0.01%) ⬇️
file-ft-tests 69.76% <96.66%> (+0.08%) ⬆️
file-ft-tests-null-compat 70.24% <96.66%> (+0.10%) ⬆️
kmip-ft-tests 28.00% <20.00%> (+<0.01%) ⬆️
mongo-v0-ft-tests 70.85% <96.66%> (+0.08%) ⬆️
mongo-v1-ft-tests 70.85% <96.66%> (+0.08%) ⬆️
multiple-backend 35.91% <13.33%> (-0.03%) ⬇️
s3c-ft-tests-v0 64.77% <70.00%> (-0.02%) ⬇️
s3c-ft-tests-v0-null-compat 63.00% <70.00%> (-1.84%) ⬇️
s3c-ft-tests-v0-replication-compat 64.62% <70.00%> (-0.02%) ⬇️
s3c-ft-tests-v1 64.75% <70.00%> (-0.01%) ⬇️
sur-tests 36.39% <20.00%> (-0.01%) ⬇️
sur-tests-inflights 39.19% <20.00%> (-0.04%) ⬇️
unit 75.29% <96.66%> (+0.03%) ⬆️
utapi-v2-tests 35.17% <20.00%> (-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.

@nicolas2bert
nicolas2bert force-pushed the bugfix/CLDSRV-1099-validate-grant-headers branch from bf37cd8 to ed5fb8f Compare December 5, 2026 13:24
it('should store a canonical id given in upper case in lower case on CopyObject', async () => {
assertOk(await request(withGrant(apis[3].params, `id=${otherId.toUpperCase()}`)));
const { res } = await request({ method: 'GET', objectKey: 'copy', queryObj: { acl: '' } });
assert(res.body.includes(`<ID>${otherId}</ID>`), res.body);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Prefer assert.match over includes so a failure shows the body and the expected pattern.

Suggested change
assert(res.body.includes(`<ID>${otherId}</ID>`), res.body);
assert.match(res.body, new RegExp(`<ID>${otherId}</ID>`));

@nicolas2bert
nicolas2bert force-pushed the bugfix/CLDSRV-1099-validate-grant-headers branch from ed5fb8f to fb04f04 Compare December 5, 2026 13:29

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.

2 participants