Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenko/cloudserver",
"version": "9.2.27",
"version": "9.2.28",
"description": "Zenko CloudServer, an open-source Node.js implementation of a server handling the Amazon S3 protocol",
"main": "index.js",
"engines": {
Expand All @@ -21,7 +21,7 @@
"dependencies": {
"@azure/storage-blob": "^12.28.0",
"@hapi/joi": "^17.1.1",
"arsenal": "git+https://github.com/scality/arsenal#8.2.45",
"arsenal": "git+https://github.com/scality/arsenal#8.2.46",
"async": "2.6.4",
"aws-sdk": "^2.1692.0",
"bucketclient": "scality/bucketclient#8.2.7",
Expand Down
80 changes: 80 additions & 0 deletions tests/functional/raw-node/test/malformedDateHeader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const assert = require('assert');
const http = require('http');

const bucket = 'test-bucket';
const objectKey = 'test-file.txt';

describe('malformed Date header:', () => {
it('should return AccessDenied for bad date with x-amz-content-sha256 header', done => {
const options = {
hostname: 'localhost',
port: 8000,
path: `/${bucket}/${objectKey}`,
method: 'GET',
headers: {
'Date': 'BAD_DATE',
'Authorization': 'AWS4-HMAC-SHA256 Credential=accessKey1/20260211/us-east-1/s3/aws4_request, ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the fixed date in the authorization is it going to work any other day ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We test the Date, before the Authorization so it does not matter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also check the error string Authentication requires a valid Date or x-amz-date header, so it we fail for another reason we would find out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put that comment direct into code so we know when we read it next time

'SignedHeaders=host, Signature=d459d5b2a2395b4c65d8f8aa2729b22c5abb04614fafbd93ab4fe203e76d21a3',
'X-Amz-Content-Sha256': 'fa8d015f89da2a769d1cea7e3bd77a5670d098d7844cda148a40c1304e5b778b',
'Host': 'localhost:8000'
}
};

const req = http.request(options, res => {
let body = '';
res.on('data', chunk => {
body += chunk;
});
res.on('end', () => {
assert.strictEqual(res.statusCode, 403, 'Server should return 403 AccessDenied for malformed Date');
assert(body.includes('AccessDenied'), 'Response should contain AccessDenied');
assert(body.includes('Authentication requires a valid Date or x-amz-date header'));
done();
});
});

req.on('error', err => {
// If we get ECONNRESET or similar, it means the server crashed
assert.fail(`Server crashed or connection error: ${err.message}`);
});

req.end();
});

it('should return AccessDenied for bad x-amz-date with x-amz-content-sha256 header', done => {
const options = {
hostname: 'localhost',
port: 8000,
path: `/${bucket}/${objectKey}`,
method: 'GET',
headers: {
'X-Amz-Date': 'BAD_DATE',
'Authorization': 'AWS4-HMAC-SHA256 Credential=accessKey1/20260211/us-east-1/s3/aws4_request, ' +
'SignedHeaders=host;x-amz-date, ' +
'Signature=d459d5b2a2395b4c65d8f8aa2729b22c5abb04614fafbd93ab4fe203e76d21a3',
'X-Amz-Content-Sha256': 'fa8d015f89da2a769d1cea7e3bd77a5670d098d7844cda148a40c1304e5b778b',
'Host': 'localhost:8000'
}
};

const req = http.request(options, res => {
let body = '';
res.on('data', chunk => {
body += chunk;
});
res.on('end', () => {
assert.strictEqual(res.statusCode, 403, 'Server should return 403 AccessDenied for malformed Date');
assert(body.includes('AccessDenied'), 'Response should contain AccessDenied');
assert(body.includes('Authentication requires a valid Date or x-amz-date header'));
done();
});
});

req.on('error', err => {
// If we get ECONNRESET or similar, it means the server crashed
assert.fail(`Server crashed or connection error: ${err.message}`);
});

req.end();
});
});
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1527,9 +1527,9 @@ arraybuffer.prototype.slice@^1.0.4:
optionalDependencies:
ioctl "^2.0.2"

"arsenal@git+https://github.com/scality/arsenal#8.2.45":
version "8.2.45"
resolved "git+https://github.com/scality/arsenal#af610f2510084a6e12a7c4c38b85eeb24a0e468c"
"arsenal@git+https://github.com/scality/arsenal#8.2.46":
version "8.2.46"
resolved "git+https://github.com/scality/arsenal#f241d4e2f292944d6bdb40789eec6085aa5fe7a2"
dependencies:
"@azure/identity" "^4.13.0"
"@azure/storage-blob" "^12.28.0"
Expand Down
Loading