Repository navigation
CLDSRV-1100: Check each grant of an ACL XML body before reading it #6423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nicolas2bert
wants to merge
1
commit into
development/9.4
Choose a base branch
from
bugfix/CLDSRV-1100-validate-acl-xml-grants
base: development/9.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| const assert = require('assert'); | ||
|
|
||
| const { makeS3Request } = require('../utils/makeRequest'); | ||
|
|
||
| const authCredentials = { | ||
| accessKey: 'accessKey1', | ||
| secretKey: 'verySecretKey1', | ||
| }; | ||
| const ownerId = '79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be'; | ||
| const bucket = 'rawnode-acl-xml-grants'; | ||
| const objectKey = 'src'; | ||
| const allUsers = 'http://acs.amazonaws.com/groups/global/AllUsers'; | ||
| const xsi = 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'; | ||
|
|
||
| // We use raw requests so the XML body reaches the server as we wrote it. A | ||
| // worker that crashes closes the socket, so the request fails with no status | ||
| // code. | ||
| function request(params) { | ||
| const headers = { 'content-length': Buffer.byteLength(params.requestBody || ''), ...params.headers }; | ||
| return new Promise(resolve => { | ||
| makeS3Request({ authCredentials, bucket, ...params, headers }, (err, res) => resolve({ err, res })); | ||
| }); | ||
| } | ||
|
|
||
| function assertError({ err, res }, statusCode, code) { | ||
| assert(res, `expected a ${statusCode} ${code}, got ${err && err.message}`); | ||
| assert.strictEqual(res.statusCode, statusCode); | ||
| assert.strictEqual(err && err.code, code); | ||
| } | ||
|
|
||
| function assertOk({ err, res }) { | ||
| assert(res, `expected a 200, got ${err && err.message}`); | ||
| assert.strictEqual(res.statusCode, 200, err && err.code); | ||
| } | ||
|
|
||
| function aclXml(grants) { | ||
| return ( | ||
| '<AccessControlPolicy>' + | ||
| `<Owner><ID>${ownerId}</ID></Owner>` + | ||
| `<AccessControlList>${grants}</AccessControlList>` + | ||
| '</AccessControlPolicy>' | ||
| ); | ||
| } | ||
|
|
||
| function groupGrant(uri) { | ||
| return `<Grant><Grantee ${xsi} xsi:type="Group"><URI>${uri}</URI></Grantee><Permission>READ</Permission></Grant>`; | ||
| } | ||
|
|
||
| const apis = [ | ||
| { name: 'PutBucketAcl', params: { queryObj: { acl: '' } } }, | ||
| { name: 'PutObjectAcl', params: { objectKey, queryObj: { acl: '' } } }, | ||
| ]; | ||
|
|
||
| // AWS returns MalformedACLError for each grant below. | ||
| const missingElements = { | ||
| 'a Grant without Grantee': '<Grant><Permission>READ</Permission></Grant>', | ||
| 'a Grant without Permission': `<Grant><Grantee ${xsi} xsi:type="CanonicalUser"><ID>${ownerId}</ID></Grantee></Grant>`, | ||
| 'a CanonicalUser without ID': `<Grant><Grantee ${xsi} xsi:type="CanonicalUser"></Grantee><Permission>READ</Permission></Grant>`, | ||
| 'a Group without URI': `<Grant><Grantee ${xsi} xsi:type="Group"></Grantee><Permission>READ</Permission></Grant>`, | ||
| }; | ||
|
|
||
| const outsideSchema = { | ||
| 'an unknown grantee type': `<Grant><Grantee ${xsi} xsi:type="Bogus"><ID>${ownerId}</ID></Grantee><Permission>READ</Permission></Grant>`, | ||
| 'the grantee type __proto__': `<Grant><Grantee ${xsi} xsi:type="__proto__"><ID>${ownerId}</ID></Grantee><Permission>READ</Permission></Grant>`, | ||
| 'an unknown permission': `<Grant><Grantee ${xsi} xsi:type="CanonicalUser"><ID>${ownerId}</ID></Grantee><Permission>BOGUS</Permission></Grant>`, | ||
| }; | ||
|
|
||
| describe('ACL XML bodies with bad grants', () => { | ||
| before(async () => { | ||
| assertOk(await request({ method: 'PUT' })); | ||
| assertOk(await request({ method: 'PUT', objectKey, requestBody: 'body' })); | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await request({ method: 'DELETE', objectKey }); | ||
| await request({ method: 'DELETE' }); | ||
| }); | ||
|
|
||
| apis.forEach(api => { | ||
| describe(api.name, () => { | ||
| // Every case starts from an ACL with one AllUsers READ grant, so we | ||
| // can check that a refused request leaves it as it was. | ||
| beforeEach(async () => { | ||
| assertOk(await request({ ...api.params, method: 'PUT', requestBody: aclXml(groupGrant(allUsers)) })); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| const { res } = await request({ ...api.params, method: 'GET' }); | ||
| assert(res.body.includes(`<URI>${allUsers}</URI>`), 'the ACL changed'); | ||
| }); | ||
|
|
||
| Object.entries({ ...missingElements, ...outsideSchema }).forEach(([name, grant]) => { | ||
| it(`should return MalformedACLError for ${name}`, async () => { | ||
| const result = await request({ ...api.params, method: 'PUT', requestBody: aclXml(grant) }); | ||
| assertError(result, 400, 'MalformedACLError'); | ||
| }); | ||
| }); | ||
|
|
||
| it('should return InvalidArgument once for two invalid group URIs', async () => { | ||
| const body = aclXml(groupGrant('http://bogus/1') + groupGrant('http://bogus/2')); | ||
| assertError(await request({ ...api.params, method: 'PUT', requestBody: body }), 400, 'InvalidArgument'); | ||
| assertOk(await request({ method: 'GET' })); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer
assert.matchoverincludesso a failure shows the actual body.