
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Use basic auth from environments variables for express.
$ npm install --save htenv
Simple express server :
// index.js
const app = require('express')()
const htenv = require('htenv')
app.use(
htenv({
/* options */
})
)
app.get('/', (req, res, next) => {
res.send('Hello.')
})
app.listen(8080, () => console.log('Server started'))
For nextjs server :
const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')
const htenv = require('htenv')
const dev = process.env.NODE_ENV !== 'production'
const PORT = process.env.PORT || 8080
const app = next({ dev })
const handle = app.getRequestHandler()
app.prepare().then(() => {
createServer(async (req, res) => {
const allowed = await htenv()(req, res)
if (allowed) {
const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl)
}
}).listen(PORT, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:' + PORT)
})
})
And run with env vars :
$ HTPASSWD=john:\$apr1\$5lF5WhAG\$SfmLYeIAMTTqSnFrwd1tt0 node index.js # pass is 42
You can use many with append random chars :
$ HTPASSWD=john:\$apr1\$5lF5WhAG\$SfmLYeIAMTTqSnFrwd1tt0 \
HTPASSWD_1=john2:\$apr1\$5lF5WhAG\$SfmLYeIAMTTqSnFrwd1tt0 \
HTPASSWD_X=john3:\$apr1\$5lF5WhAG\$SfmLYeIAMTTqSnFrwd1tt0 \
node index.js
Be carfull with $ chars : Add backslash in bash, double it on docker-compose.yml :
services:
app:
image: node
command: cd /app && npm run start
volumes:
- '.:/app'
environment:
HTPASSWD: "john:$$apr1$$5lF5WhAG$$SfmLYeIAMTTqSnFrwd1tt0"
HTPASSWD_1: "john2:$$apr1$$5lF5WhAG$$SfmLYeIAMTTqSnFrwd1tt0"
HTPASSWD_X: "john3:$$apr1$$5lF5WhAG$$SfmLYeIAMTTqSnFrwd1tt0"
key (default 'HTPASSWD') : Start of environment variables namerealm (default 'Restricted area') : Message on the popupapp.use(
htenv({
key: 'MY_CUSTOM_ACCESS',
realm: 'Who are you ?',
})
)
FAQs
Use basic auth from environments variables for express.
We found that htenv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.