@authuser/nest 0.2.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,45 @@
1
+ # Production checklist
2
+
3
+ Use this list before exposing a service to untrusted traffic.
4
+
5
+ ## Application
6
+
7
+ - Start from the `secure` preset and document every disabled control.
8
+ - Authenticate and authorize sensitive routes with application guards.
9
+ - Keep `Public()` usage explicit and covered by authorization tests.
10
+ - Validate business rules, file uploads and data leaving persistence layers.
11
+ - Use `nest.logger` and `observability.logger` intentionally.
12
+
13
+ ## Network and edge
14
+
15
+ - Terminate TLS at a trusted edge and redirect plaintext traffic.
16
+ - Configure `network.trustProxy` only for known proxy addresses or networks.
17
+ - Apply an infrastructure-level request/body limit no larger than the application
18
+ limit where possible.
19
+ - Tune connection, header, request and handler timeouts against production latency.
20
+ - Use an upstream DDoS control for an internet-facing API.
21
+
22
+ ## Distributed operation
23
+
24
+ - Configure Redis or another shared `@fastify/rate-limit` store for multiple replicas.
25
+ - Give login, recovery and expensive routes stricter endpoint-specific limits.
26
+ - Keep liveness independent of downstream dependencies.
27
+ - Put database, queue and critical service checks in readiness.
28
+ - Ensure the orchestrator removes a replica when readiness returns 503.
29
+
30
+ ## Exposure and data
31
+
32
+ - Disable or protect Swagger UI and OpenAPI in production.
33
+ - Do not return credentials or topology from health checks.
34
+ - Keep secrets and personal data out of URLs and logs.
35
+ - Keep JSON log redaction enabled and extend it for application-specific fields.
36
+ - Add CSRF protection when browsers authenticate with ambient cookies.
37
+
38
+ ## Release
39
+
40
+ - Run `npm run check`, `npm run test:coverage`, `npm run test:package`, and
41
+ `npm run smoke --prefix example`.
42
+ - Review `npm audit --omit=dev` and dependency updates.
43
+ - Load-test realistic payloads through the production proxy and TLS path.
44
+ - Exercise shutdown while requests are active.
45
+ - Monitor latency percentiles, error rate, event-loop utilization and memory.
@@ -0,0 +1,28 @@
1
+ # Release process
2
+
3
+ ## Preparation
4
+
5
+ 1. Ensure `main` is green and the worktree is clean.
6
+ 2. Update `CHANGELOG.md` and the package version using Semantic Versioning.
7
+ 3. Run `npm run check`, `npm run test:coverage`, `npm run test:package`, and
8
+ `npm run smoke --prefix example`.
9
+ 4. Commit the release and create an annotated `vX.Y.Z` tag at that commit.
10
+ 5. Push the commit and tag.
11
+
12
+ ## Trusted publishing
13
+
14
+ Configure npm trusted publishing for:
15
+
16
+ - Organization/user: `authuser-org`
17
+ - Repository: `nest`
18
+ - Workflow: `.github/workflows/release.yml`
19
+ - Environment: `npm`
20
+
21
+ Create a GitHub Release from the version tag. The release workflow verifies that the
22
+ tag equals `package.json`, repeats all release checks, and publishes with npm
23
+ provenance through GitHub OIDC. No long-lived npm token should be stored in GitHub.
24
+
25
+ ## Verification
26
+
27
+ Confirm the npm version and provenance, install it into a clean project, and verify
28
+ that the GitHub tag resolves to the same commit used by the release workflow.
package/docs/security.md CHANGED
@@ -9,11 +9,17 @@ The secure preset establishes a baseline, not a complete application security mo
9
9
  - A one MiB default request-body limit.
10
10
  - Finite connection, request, handler and header timeouts.
11
11
  - Rate limiting by client IP.
12
- - Request IDs restricted to 128 safe characters before log propagation.
13
- - Generic internal errors; unexpected exceptions are logged server-side only.
12
+ - `createApp` request IDs restricted to 128 safe characters before log propagation.
13
+ - Correlation IDs returned to clients in a configurable response header.
14
+ - Reserved HTTP framing, connection and authentication headers cannot be reused as
15
+ the correlation-response header.
16
+ - Generic 5xx errors; unexpected exceptions are logged server-side only.
14
17
  - CORS disabled until an allowlist is configured.
15
18
  - Sensitive authentication and cookie log fields redacted by default.
19
+ - Query strings excluded from default request logs and error response paths.
16
20
  - Optional pre-handler protection for documentation and health routes.
21
+ - Dynamic readiness checks that fail closed without exposing dependency errors.
22
+ - Runtime configuration validation for JavaScript and environment-derived options.
17
23
 
18
24
  ## Application responsibilities
19
25
 
@@ -26,11 +32,17 @@ The secure preset establishes a baseline, not a complete application security mo
26
32
  - Use TLS at the load balancer or application edge.
27
33
  - Keep Node and dependencies patched and review `npm audit` output.
28
34
  - Avoid exposing Swagger UI and detailed readiness data publicly.
35
+ - Keep credentials, tokens and personal data out of URL query parameters.
36
+ - Preserve the default request serializer, or redact equivalent data in a custom
37
+ Pino `serializers.req` implementation.
29
38
  - Add CSRF protection when authentication relies on ambient cookies or sessions.
30
39
 
31
40
  `Public()` and `Roles()` only attach metadata. They do nothing until an application
32
41
  guard reads that metadata and enforces the intended policy.
33
42
 
43
+ Setting `errors: false` or providing a custom filter transfers responsibility for
44
+ 5xx redaction and safe error contracts to the consuming application.
45
+
34
46
  ## Reporting
35
47
 
36
48
  Follow the private disclosure instructions in [SECURITY.md](../SECURITY.md).
@@ -0,0 +1,41 @@
1
+ # Threat model
2
+
3
+ `@authuser/nest` hardens the HTTP process boundary for a Nest application. It does
4
+ not establish user identity or decide whether a caller may access a business object.
5
+
6
+ ## Protected assets
7
+
8
+ - Availability of the Node process and its event loop.
9
+ - Confidentiality of request credentials and internal exception details.
10
+ - Integrity of parsed JSON objects and request correlation identifiers.
11
+ - Predictable application bootstrap and shutdown behavior.
12
+
13
+ ## Included mitigations
14
+
15
+ - Bounded bodies, parameters, sockets and finite timeouts reduce common resource
16
+ exhaustion paths.
17
+ - Prototype and constructor poisoning are rejected during JSON parsing.
18
+ - Helmet establishes browser-facing security headers.
19
+ - Strict DTO defaults reject unexpected properties.
20
+ - CORS is closed until explicitly configured.
21
+ - Rate limiting controls abusive clients per instance or shared store.
22
+ - Incoming request IDs are validated by `createApp` before they reach logs.
23
+ - Sensitive headers and query strings are excluded from default logs.
24
+ - All 5xx details and health-check failures are hidden from clients.
25
+
26
+ ## Explicitly out of scope
27
+
28
+ - Authentication, authorization, tenancy and object-level access control.
29
+ - TLS termination, WAF, network policy and volumetric DDoS protection.
30
+ - Database query construction, encryption, secret storage and key rotation.
31
+ - CSRF defenses for cookie-authenticated applications.
32
+ - Malware scanning, file validation and non-HTTP ingestion.
33
+
34
+ ## Trust assumptions
35
+
36
+ - Nest, Fastify and direct dependencies are kept on supported patched versions.
37
+ - `trustProxy` contains only infrastructure controlled by the operator.
38
+ - A distributed deployment uses a shared rate-limit store.
39
+ - Application code does not deliberately log or expose sensitive data.
40
+ - Applications calling `configureHttpApp` directly configure equivalent request-ID
41
+ and network limits on their own Fastify adapter.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authuser/nest",
3
- "version": "0.2.2",
3
+ "version": "1.1.0",
4
4
  "description": "Secure, high-performance NestJS foundation powered by Fastify",
5
5
  "keywords": [
6
6
  "nestjs",
@@ -19,17 +19,23 @@
19
19
  ".": {
20
20
  "types": "./dist/index.d.ts",
21
21
  "import": "./dist/index.js",
22
+ "require": "./dist/index.js",
22
23
  "default": "./dist/index.js"
23
- }
24
+ },
25
+ "./package.json": "./package.json"
24
26
  },
25
27
  "files": [
26
28
  "dist",
27
29
  "docs",
28
30
  "README.md",
29
31
  "CHANGELOG.md",
32
+ "SECURITY.md",
33
+ "SUPPORT.md",
30
34
  "LICENSE"
31
35
  ],
32
- "sideEffects": false,
36
+ "sideEffects": [
37
+ "./dist/index.js"
38
+ ],
33
39
  "engines": {
34
40
  "node": ">=22.12"
35
41
  },
@@ -43,8 +49,10 @@
43
49
  "typecheck": "tsc -p tsconfig.json --noEmit",
44
50
  "test": "vitest run",
45
51
  "test:coverage": "vitest run --coverage",
52
+ "test:package": "npm run build && node scripts/verify-package.mjs",
46
53
  "benchmark": "npm run build && node benchmark/run.mjs",
47
54
  "prepack": "npm run clean && npm run build",
55
+ "prepublishOnly": "npm run check && npm run test:package",
48
56
  "check": "npm run typecheck && npm test && npm run build && npm pack --dry-run"
49
57
  },
50
58
  "dependencies": {