-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modular: removes Morgan in favor of custom logging middleware
- Loading branch information
1 parent
e960f5d
commit 1b598cb
Showing
23 changed files
with
176 additions
and
195 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
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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
const { logRequest } = require('../logger'); | ||
|
||
/** sanity check of username, to defend against ".." and whatnot */ | ||
module.exports = function sanityCheckUsername (req, res, next) { | ||
const username = req.params.username || req.data.username || ''; | ||
if (username.length > 0 && !/\/|^\.+$/.test(username) && /[\p{Lu}\p{Ll}\p{Lt}\p{Lo}\p{Nd}]{1,63}/u.test(username)) { | ||
return next(); | ||
} | ||
|
||
res.status(400).type('text/plain').end(); | ||
|
||
logRequest(req, req.data.username, 400, 0, 'invalid user'); | ||
res.logNotes.add('invalid user'); | ||
res.status(400).end(); | ||
}; |
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
const isSecureRequest = require('../util/isSecureRequest'); | ||
const { logRequest } = require('../logger'); | ||
|
||
/** ensures request is secure, if required */ | ||
module.exports = function secureRequest (req, res, next) { | ||
if (isSecureRequest(req) || (process.env.NODE_ENV !== 'production' && !req.app.get('forceSSL'))) { | ||
return next(); | ||
} | ||
|
||
res.status(400).end(); // TODO: add an explanatory message | ||
logRequest(req, '-', 400, 0, 'blocked insecure'); | ||
res.logNotes.add('blocked insecure'); | ||
res.status(400).type('text/plain').send('The request did not use HTTPS.'); | ||
}; |
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
Oops, something went wrong.