Skip to content
This repository has been archived by the owner on Jul 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from herber/fix-open-redirect
Browse files Browse the repository at this point in the history
implement fix for "open redirect when target domain name is used as html filename on server"
  • Loading branch information
herber committed Apr 12, 2018
2 parents c33aaae + 408dd52 commit 1e5c75f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion bin/hekto.js
Expand Up @@ -39,6 +39,13 @@ if (args.v || args.version) {

args._.splice(0, 1);

const stripTrailingSlash = (str) => {
if(str.substr(-1) === '/') {
return str.substr(0, str.length - 1);
}
return str;
}

/*
if `serve` command is passed in
*/
Expand Down Expand Up @@ -184,7 +191,7 @@ if (args.serve) {
// Add trailing slash for extensionless html
if (fs.existsSync(file + '.html') && fs.lstatSync(file + '.html').isFile()) {
this.status = 307;
this.redirect(this.request.url + '/' + query);
this.redirect(this.request.origin + stripTrailingSlash(this.request.url) + '/' + query);

return ;
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -4,7 +4,7 @@
"url": "https://github.com/tobihrbr/hekto.git",
"type": "git"
},
"version": "0.2.3",
"version": "0.2.4",
"description": "Serve static files",
"keywords": [
"serve",
Expand Down

0 comments on commit 1e5c75f

Please sign in to comment.