Serving sensitive files such as dotfiles are not recommended as they contains sensitive information.
Hidden files are created automatically by many tools to save user-preferences; well-known examples are .profile
, .bashrc
, .bash_history
or .git
. To simplify the view these files are not displayed by default using operating system commands like ls
.
Outside of the user environment, hidden files are sensitive because they are used to store private information or even hard-coded secrets.
Recommended Secure Coding Practices : Disable the serving of hidden files.
const serveStatic = require('serve-static')
let serveStaticMiddleware = serveStatic('public', {
index: false,
dotfiles: 'allow' // not safe
})
const serveStatic = require('serve-static')
let serveStaticMiddleware = serveStatic('public', {
index: false,
dotfiles: 'ignore' // Compliant
})