-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add validateFilepath util to check req.path is correct format
- Loading branch information
1 parent
f486216
commit 6ba74bb
Showing
3 changed files
with
22 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import path from 'path'; | ||
import * as config from '../config'; | ||
import { Request, Response } from 'express'; | ||
|
||
// https://codeql.github.com/codeql-query-help/javascript/js-path-injection/ | ||
|
||
export const validateFilepath = (req: Request, res: Response): string | void => { | ||
|
||
const unsanitizedPath = req.path; | ||
|
||
// Check if the normalised path is within the root directory | ||
if (path.resolve(unsanitizedPath).startsWith(config.ROOT)) { | ||
return req.path; | ||
} else { | ||
return res.render(config.ERROR_PAGE); | ||
} | ||
}; |