Skip to content

Commit

Permalink
fix log injection vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusccortes committed Nov 23, 2023
1 parent eaca2cf commit 8ccacf0
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions app/routes/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ function SessionHandler(db) {
password
} = req.body;
userDAO.validateLogin(userName, password, (err, user) => {
const errorMessage = "Invalid username and/or password";
const invalidUserNameErrorMessage = "Invalid username";
const invalidPasswordErrorMessage = "Invalid password";
if (err) {
Expand All @@ -66,18 +65,14 @@ function SessionHandler(db) {
// Fix for A1 - 3 Log Injection - encode/sanitize input for CRLF Injection
// that could result in log forging:
// - Step 1: Require a module that supports encoding
// const ESAPI = require('node-esapi');
const ESAPI = require('node-esapi');
// - Step 2: Encode the user input that will be logged in the correct context
// following are a few examples:
// console.log('Error: attempt to login with invalid user: %s',
// ESAPI.encoder().encodeForHTML(userName));
// console.log('Error: attempt to login with invalid user: %s',
// ESAPI.encoder().encodeForJavaScript(userName));
// console.log('Error: attempt to login with invalid user: %s',
// ESAPI.encoder().encodeForURL(userName));
console.log('Error: attempt to login with invalid user: %s', ESAPI.encoder().encodeForHTML(userName));
console.log('Error: attempt to login with invalid user: %s', ESAPI.encoder().encodeForJavaScript(userName));
console.log('Error: attempt to login with invalid user: %s', ESAPI.encoder().encodeForURL(userName));
// or if you know that this is a CRLF vulnerability you can target this specifically as follows:
// console.log('Error: attempt to login with invalid user: %s',
// userName.replace(/(\r\n|\r|\n)/g, '_'));
console.log('Error: attempt to login with invalid user: %s', userName.replace(/(\r\n|\r|\n)/g, '_'));

return res.render("login", {
userName: userName,
Expand Down

0 comments on commit 8ccacf0

Please sign in to comment.