Skip to content

Commit d3ce5e9

Browse files
authored
Merge pull request #8954 from jackyalbo/jacky-cors-fixes
Rejecting wildcard('*') in expose headers - like AWS
2 parents 469392a + 4e2b21b commit d3ce5e9

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/endpoint/s3/ops/s3_put_bucket_cors.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ async function put_bucket_cors(req) {
1717
message: `Found unsupported HTTP method in CORS config. Unsupported method is ${unsupported_method}`
1818
});
1919
}
20+
const wildcard_expose_header = rule.ExposeHeader?.find(item => item.includes('*'));
21+
if (wildcard_expose_header) {
22+
throw new S3Error({
23+
...S3Error.InvalidRequest,
24+
message: `ExposeHeader "${wildcard_expose_header}" contains wildcard. We currently do not support wildcard for ExposeHeader.`
25+
});
26+
}
2027
return _.omitBy({
2128
allowed_headers: rule.AllowedHeader,
2229
allowed_methods: rule.AllowedMethod,

src/test/unit_tests/test_s3_ops.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,29 @@ mocha.describe('s3_ops', function() {
532532
}
533533
});
534534

535+
mocha.it('should fail on wildcar in ExposeHeader', async function() {
536+
const wildcard_expose_header = "x-amz-server-side-*";
537+
const params = {
538+
Bucket: "cors-bucket",
539+
CORSConfiguration: {
540+
CORSRules: [{
541+
AllowedOrigins: ["http://www.example.com"],
542+
AllowedMethods: ["PUT", "POST", "DELETE"],
543+
ExposeHeaders: ["Content-Length", wildcard_expose_header]
544+
}]
545+
}
546+
};
547+
try {
548+
await s3.putBucketCors(params);
549+
assert.fail(`should reject put bucket cors with wildcar expose header ${wildcard_expose_header}`);
550+
} catch (err) {
551+
assert.strictEqual(err.Code, 'InvalidRequest',
552+
`ExposeHeader "${wildcard_expose_header}" contains wildcard. We currently do not support wildcard for ExposeHeader.`
553+
);
554+
assert.strictEqual(err.$metadata.httpStatusCode, 400);
555+
}
556+
});
557+
535558
mocha.after(async function() {
536559
await s3.deleteBucket({ Bucket: "cors-bucket" });
537560
});

0 commit comments

Comments
 (0)