Skip to content

Commit

Permalink
fix: hide from public directory only file whose basename start with a…
Browse files Browse the repository at this point in the history
… dot (#206)
  • Loading branch information
matteo-cristino authored Jun 11, 2024
1 parent b453e16 commit e39d441
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions public/.test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This should not be reachable!
1 change: 1 addition & 0 deletions public/.test/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This should be reachable!
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Dir.ready(async () => {
res.onAborted(() => {
res.writeStatus('500').end('Aborted');
});
if (req.getUrl().replace(/^\/+/g, '/').startsWith('/.')) return res.writeStatus('404 Not Found').end('Not found');
if (req.getUrl().split('/').pop().startsWith('.')) return res.writeStatus('404 Not Found').end('Not found');
let file = path.join(publicDirectory, req.getUrl());
if (fs.existsSync(file)) {
let contentType = mime.getType(file) || 'application/json';
Expand Down
15 changes: 14 additions & 1 deletion tests/workflow.stepci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,17 @@ tests:
title: Benvenuto
body: Hello World!
headers:
Content-Type: text/html
Content-Type: text/html
- name: unreachable file since its basename start with a dot
http:
url: http://${{env.host}}/.test.txt
method: GET
check:
status: 404
- name: reachable file since its filepath start with a dot, but not its basename
http:
url: http://${{env.host}}/.test/test.txt
method: GET
check:
status: 200
body: This should be reachable!

0 comments on commit e39d441

Please sign in to comment.