Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 12 additions & 106 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,132 +14,38 @@ jobs:
fail-fast: false
matrix:
name:
- Node.js 0.10
- Node.js 0.12
- io.js 1.x
- io.js 2.x
- io.js 3.x
- Node.js 4.x
- Node.js 5.x
- Node.js 6.x
- Node.js 7.x
- Node.js 8.x
- Node.js 9.x
- Node.js 10.x
- Node.js 11.x
- Node.js 12.x
- Node.js 13.x
- Node.js 14.x
- Node.js 15.x
- Node.js 22.x
- Node.js 24.x
- Node.js 26.x

include:
- name: Node.js 0.10
node-version: "0.10"
npm-i: mocha@3.5.3 rimraf@2.7.1 supertest@2.0.0

- name: Node.js 0.12
node-version: "0.12"
npm-i: mocha@3.5.3 rimraf@2.7.1 supertest@2.0.0

- name: io.js 1.x
node-version: "1.8"
npm-i: mocha@3.5.3 rimraf@2.7.1 supertest@2.0.0

- name: io.js 2.x
node-version: "2.5"
npm-i: mocha@3.5.3 rimraf@2.7.1 supertest@2.0.0

- name: io.js 3.x
node-version: "3.3"
npm-i: mocha@3.5.3 rimraf@2.7.1 supertest@2.0.0

- name: Node.js 4.x
node-version: "4.9"
npm-i: mocha@5.2.0 rimraf@2.7.1 supertest@3.4.2

- name: Node.js 5.x
node-version: "5.12"
npm-i: mocha@5.2.0 rimraf@2.7.1 supertest@3.4.2

- name: Node.js 6.x
node-version: "6.17"
npm-i: mocha@6.2.3

- name: Node.js 7.x
node-version: "7.10"
npm-i: mocha@6.2.3

- name: Node.js 8.x
node-version: "8.17"
npm-i: mocha@7.2.0

- name: Node.js 9.x
node-version: "9.11"
npm-i: mocha@7.2.0

- name: Node.js 10.x
node-version: "10.24"
npm-i: mocha@8.4.0

- name: Node.js 11.x
node-version: "11.15"
npm-i: mocha@8.4.0

- name: Node.js 12.x
node-version: "12.22"

- name: Node.js 13.x
node-version: "13.14"

- name: Node.js 14.x
node-version: "14.18"

- name: Node.js 15.x
node-version: "15.14"
- name: Node.js 22.x
node-version: "22"
- name: Node.js 24.x
node-version: "24"
- name: Node.js 26.x
node-version: "26"

steps:
- uses: actions/checkout@v4

- name: Install Node.js ${{ matrix.node-version }}
shell: bash -eo pipefail -l {0}
run: |
nvm install --default ${{ matrix.node-version }}
dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH"

- name: Configure npm
run: npm config set shrinkwrap false

- name: Install npm module(s) ${{ matrix.npm-i }}
run: npm install --save-dev ${{ matrix.npm-i }}
if: matrix.npm-i != ''

- name: Setup Node.js version-specific dependencies
shell: bash
run: |
# eslint for linting
# - remove on Node.js < 10
if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then
node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \
grep -E '^eslint(-|$)' | \
sort -r | \
xargs -n1 npm rm --silent --save-dev
fi
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install Node.js dependencies
run: npm install

- name: List environment
id: list_env
shell: bash
run: |
echo "node@$(node -v)"
echo "npm@$(npm -v)"
npm -s ls ||:
(npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print "::set-output name=" $2 "::" $3 }'

- name: Run tests
run: npm run test-ci

- name: Lint code
if: steps.list_env.outputs.eslint != ''
run: npm run lint
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ This generator can also be further configured with the following command line fl
-f, --force force on non-empty directory
-h, --help output usage information

## Security

Generated applications require Node.js `>= 22.12` and come with extra protections:

- `safe-blocklist-http-server` wraps the HTTP server with IP blocking, rate limiting and blocking of common attack endpoints (`/wp-admin`, `/.env`, `/.git/config`, ...). The blocklist is persisted in `blocklist.json`.
- `express-defend`, `express-blacklist` and `dddos` filter suspicious requests inside Express.
- Sessions are stored in an `HttpOnly` cookie encrypted with authenticated AES-256-GCM via `aes512`.

Set the `SESSION_SECRET` environment variable to keep sessions valid across restarts (a random secret is generated otherwise):

```bash
$ SESSION_SECRET=your-secret npm start
```

## License

[MIT](LICENSE)
Expand Down
16 changes: 13 additions & 3 deletions bin/express-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ function createApplication (name, dir, options, done) {
scripts: {
start: 'node ./bin/www'
},
engines: {
node: '>=22.12'
},
dependencies: {
debug: '~2.6.9',
express: '~4.17.1'
Expand All @@ -115,6 +118,7 @@ function createApplication (name, dir, options, done) {
app.locals.modules = Object.create(null)
app.locals.mounts = []
app.locals.uses = []
app.locals.css = options.css

// Request logger
app.locals.modules.logger = 'morgan'
Expand All @@ -130,6 +134,13 @@ function createApplication (name, dir, options, done) {
app.locals.uses.push('cookieParser()')
pkg.dependencies['cookie-parser'] = '~1.4.5'

// Session and network security
pkg.dependencies.aes512 = '^2.0.6'
pkg.dependencies.dddos = '^0.1.2'
pkg.dependencies['express-blacklist'] = '^1.0.3'
pkg.dependencies['express-defend'] = '^1.0.9'
pkg.dependencies['safe-blocklist-http-server'] = '^1.0.8'

if (dir !== '.') {
mkdir(dir, '.')
}
Expand Down Expand Up @@ -210,9 +221,8 @@ function createApplication (name, dir, options, done) {
pkg.dependencies['less-middleware'] = '~2.2.1'
break
case 'sass':
app.locals.modules.sassMiddleware = 'node-sass-middleware'
app.locals.uses.push("sassMiddleware({\n src: path.join(__dirname, 'public'),\n dest: path.join(__dirname, 'public'),\n indentedSyntax: true, // true = .sass and false = .scss\n sourceMap: true\n})")
pkg.dependencies['node-sass-middleware'] = '0.11.0'
app.locals.uses.push('sassMiddleware')
pkg.dependencies.sass = '^1.108.1'
break
case 'stylus':
app.locals.modules.stylus = 'stylus'
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "express-generator",
"name": "express-security-generator",
"description": "Express' application generator",
"version": "4.16.1",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
Expand All @@ -25,16 +25,16 @@
"repository": "expressjs/generator",
"license": "MIT",
"dependencies": {
"ejs": "2.6.2",
"minimatch": "3.0.4",
"minimist": "1.2.5",
"ejs": "3.1.10",
"minimatch": "3.1.4",
"minimist": "1.2.6",
"mkdirp": "0.5.1",
"sorted-object": "2.0.1"
},
"main": "bin/express-cli.js",
"preferGlobal": true,
"bin": {
"express": "./bin/express-cli.js"
"express-security": "./bin/express-cli.js"
},
"devDependencies": {
"eslint": "7.32.0",
Expand All @@ -43,15 +43,15 @@
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.2.0",
"eslint-plugin-standard": "4.1.0",
"mocha": "9.1.3",
"mocha": "12.0.3",
"rimraf": "3.0.2",
"supertest": "6.1.4",
"tree-kill": "1.2.2",
"uid-safe": "2.1.5",
"validate-npm-package-name": "3.0.0"
},
"engines": {
"node": ">= 0.10"
"node": ">= 22.12"
},
"files": [
"LICENSE",
Expand All @@ -60,7 +60,7 @@
],
"scripts": {
"lint": "eslint .",
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-ci": "mocha --reporter spec --check-leaks test/"
"test": "mocha --reporter spec --bail --check-leaks --exit test/",
"test-ci": "mocha --reporter spec --check-leaks --exit test/"
}
}
Loading