-
Notifications
You must be signed in to change notification settings - Fork 19
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
Improvement/arsn 422 support post object #2248
Open
KazToozs
wants to merge
7
commits into
development/7.70
Choose a base branch
from
improvement/ARSN-422-support-post-object
base: development/7.70
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 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e98903b
ARSN-422: add support for POST object
1244a1d
ARSN-422: update error messages
61984fb
ARSN-422: add unit tests for formAuthCheck
5cd2814
fixup: post review
e109d2d
ARSN-422: add error for query string on post
9e824e2
fixup: post review
4ef5748
fixup: conditions in routesPOST
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 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,108 @@ | ||
import { Logger } from 'werelogs'; | ||
import * as constants from '../../constants'; | ||
import errors from '../../errors'; | ||
import { convertAmzTimeToMs } from './timeUtils'; | ||
import { validateCredentials } from './validateInputs'; | ||
|
||
/** | ||
* V4 query auth check | ||
* @param request - HTTP request object | ||
* @param log - logging object | ||
* @param data - Contain authentification params (GET or POST data) | ||
*/ | ||
export function check(request: any, log: Logger, data: { [key: string]: string }) { | ||
let signatureFromRequest; | ||
let timestamp; | ||
let expiration; | ||
let credential; | ||
|
||
if (data['x-amz-algorithm'] !== 'AWS4-HMAC-SHA256') { | ||
log.debug('algorithm param incorrect', { algo: data['X-Amz-Algorithm'] }); | ||
return { err: errors.InvalidArgument }; | ||
} | ||
|
||
signatureFromRequest = data['x-amz-signature']; | ||
if (!signatureFromRequest) { | ||
log.debug('missing signature'); | ||
return { err: errors.InvalidArgument }; | ||
} | ||
|
||
timestamp = data['x-amz-date']; | ||
if (!timestamp || timestamp.length !== 16) { | ||
log.debug('missing or invalid timestamp', { timestamp: data['x-amz-date'] }); | ||
return { err: errors.InvalidArgument }; | ||
} | ||
|
||
const policy = data['policy']; | ||
if (policy && policy.length > 0) { | ||
const decryptedPolicy = Buffer.from(policy, 'base64').toString('utf8'); | ||
const policyObj = JSON.parse(decryptedPolicy); | ||
expiration = policyObj.expiration; | ||
} else { | ||
log.debug('missing or invalid policy', { policy: data['policy'] }); | ||
return { err: errors.InvalidArgument }; | ||
} | ||
|
||
credential = data['x-amz-credential']; | ||
if (credential && credential.length > 28 && credential.indexOf('/') > -1) { | ||
// @ts-ignore | ||
credential = credential.split('/'); | ||
const validationResult = validateCredentials(credential, timestamp, | ||
log); | ||
if (validationResult instanceof Error) { | ||
log.debug('credentials in improper format', { credential, | ||
timestamp, validationResult }); | ||
return { err: validationResult }; | ||
} | ||
} else { | ||
log.debug('invalid credential param', { credential: data['X-Amz-Credential'] }); | ||
return { err: errors.InvalidArgument }; | ||
} | ||
|
||
const token = data['x-amz-security-token']; | ||
if (token && !constants.iamSecurityToken.pattern.test(token)) { | ||
log.debug('invalid security token', { token }); | ||
return { err: errors.InvalidToken }; | ||
} | ||
|
||
// check if the expiration date is past the current time | ||
if (Date.parse(expiration) < Date.now()) { | ||
return { err: errors.AccessDenied.customizeDescription('Invalid according to Policy: Policy expired.') }; | ||
} | ||
|
||
const validationResult = validateCredentials(credential, timestamp, | ||
log); | ||
if (validationResult instanceof Error) { | ||
log.debug('credentials in improper format', { credential, | ||
timestamp, validationResult }); | ||
return { err: validationResult }; | ||
} | ||
const accessKey = credential[0]; | ||
const scopeDate = credential[1]; | ||
const region = credential[2]; | ||
const service = credential[3]; | ||
|
||
// string to sign is the policy for form requests | ||
const stringToSign = data['policy']; | ||
|
||
log.trace('constructed stringToSign', { stringToSign }); | ||
return { | ||
err: null, | ||
params: { | ||
version: 4, | ||
data: { | ||
accessKey, | ||
signatureFromRequest, | ||
region, | ||
scopeDate, | ||
stringToSign, | ||
service, | ||
authType: 'REST-FORM-DATA', | ||
signatureVersion: 'AWS4-HMAC-SHA256', | ||
signatureAge: Date.now() - convertAmzTimeToMs(timestamp), | ||
timestamp, | ||
securityToken: token, | ||
}, | ||
}, | ||
}; | ||
} |
This file contains 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 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 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 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 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 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 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 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 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 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
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.
This is breaking change https://github.com/search?q=org%3Ascality+KeyTooLong+path%3A*.js+OR+path%3A*.ts+OR+path%3A*.rst+OR+path%3A*.json&type=code
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.
Ok, I'll work with the old version for CS Post Object then