-
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
base: development/7.70
Are you sure you want to change the base?
Changes from 3 commits
e98903b
1244a1d
61984fb
5cd2814
e109d2d
9e824e2
4ef5748
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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, | ||
}, | ||
}, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import * as http from 'http'; | |
export default function routePOST( | ||
request: http.IncomingMessage, | ||
response: http.ServerResponse, | ||
api: { callApiMethod: routesUtils.CallApiMethod }, | ||
api: routesUtils.ApiMethods, | ||
log: RequestLogger, | ||
) { | ||
log.debug('routing request', { method: 'routePOST' }); | ||
|
@@ -58,6 +58,10 @@ export default function routePOST( | |
corsHeaders)); | ||
} | ||
|
||
if (objectKey === undefined && Object.keys(query).length === 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also on post object aws returns a 400 instead of a 501 Not Implemented for query string
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e109d2d There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also before that if there is an <Code>MethodNotAllowed</Code>
<Message>The specified method is not allowed against this resource.</Message>
<Method>POST</Method>
<ResourceType>OBJECT</ResourceType> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like this? Tested |
||
return api.callPostObject!(request, response, log, (err, resHeaders) => routesUtils.responseNoBody(err, resHeaders, response, 204, log)); | ||
} | ||
|
||
return routesUtils.responseNoBody(errors.NotImplemented, null, response, | ||
200, log); | ||
} |
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