Skip to content

Commit

Permalink
fix(cdn): do not serve package.json or changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Dec 11, 2024
1 parent 28840f9 commit 6296a38
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export async function main(req, ctx) {
if (req.method === 'GET' && pathname.startsWith('/info.json')) {
return respondInfo(ctx);
}

// Block access to sensitive files
if (pathname.toLowerCase().includes('package.json') ||
pathname.toLowerCase().includes('changelog.md')) {
return respondError('Not Found', 404, undefined, req);
}

const isDirList = (pathname.endsWith('/'));
if (req.method === 'GET' && pathname.startsWith('/.rum/web-vitals')) {
if (isDirList) {
Expand Down
19 changes: 19 additions & 0 deletions test/post-deploy.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,24 @@ import assert from 'assert';
});
assert.strictEqual(response.status, 400);
});

it('Sensitive files return 404 - package.json', async function test() {
if (!process.env.TEST_INTEGRATION) {
this.skip();
}
const sensitiveUrls = [
'/.rum/@adobe/helix-rum-js@^2/package.json',
'/.rum/@adobe/helix-rum-js@^2/CHANGELOG.md'
];

for (const url of sensitiveUrls) {
const response = await fetch(`https://${domain}${url}`, {
method: 'GET'
});
assert.strictEqual(response.status, 404, `Expected 404 for ${url}`);
const text = await response.text();
assert.match(text, /Not Found/);
}
});
});
});

0 comments on commit 6296a38

Please sign in to comment.