Skip to content

Commit f97c507

Browse files
committed
ARSN-560: add ISO8601 check in extractQueryParams
1 parent c564daf commit f97c507

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/auth/v4/validateInputs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { RequestLogger } from 'werelogs';
22
import errors, { ArsenalError } from '../../../lib/errors';
3+
import { isValidISO8601Compact } from './timeUtils';
34
import { type ArsenalRequestHeaders } from '../../types/ArsenalRequest';
45

56
/**
@@ -103,7 +104,7 @@ export function extractQueryParams(
103104
}
104105

105106
const timestamp = queryObj['X-Amz-Date'];
106-
if (timestamp && timestamp.length === 16) {
107+
if (timestamp && isValidISO8601Compact(timestamp)) {
107108
authParams.timestamp = timestamp;
108109
} else {
109110
log.warn('missing or invalid timestamp',

tests/unit/auth/v4/queryAuthCheck.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,16 @@ describe('v4 queryAuthCheck', () => {
157157
done();
158158
});
159159

160+
it('should return error if X-Amz-Date param is before epoch time', done => {
161+
const alteredRequest = createAlteredRequest({
162+
'X-Amz-Date': '19500707T215304Z',
163+
'X-Amz-Credential': 'accessKey1/19500707/us-east-1/s3/aws4_request',
164+
}, 'query', request, query);
165+
const res = queryAuthCheck(alteredRequest, log, alteredRequest.query);
166+
assert.deepStrictEqual(res.err, errors.InvalidArgument);
167+
done();
168+
});
169+
160170
it('should return error if X-Amz-Date param is in the future', done => {
161171
// 2095 instead of 2016
162172
const alteredRequest = createAlteredRequest({

0 commit comments

Comments
 (0)