@axiumine/koa-utils 5.9.0 → 6.0.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.
package/README.md
CHANGED
|
@@ -200,14 +200,30 @@ import { StringLib } from '@axiumine/koa-utils/lib/StringLib'
|
|
|
200
200
|
| `POSTGRESQL_USER`, `_PWD`, `_HOST`, `_PORT`, `_DBNAME`, `_POOL_MAX`, `_IDLE_TIMEOUT` | PostgreSQL |
|
|
201
201
|
| `REDIS_URL` or `REDIS_IS_CLUSTER` + `REDIS_DB{1,2,3}_HOST/PORT`, `REDIS_USERNAME`, `REDIS_PASSWORD` | Redis |
|
|
202
202
|
| `REDIS_KEY` | Prefix for all keys (e.g. `myapp:`) |
|
|
203
|
-
| `INTROSPECTION_CODE` | Bypass header `x-introspectioncode` for schema introspection |
|
|
203
|
+
| `INTROSPECTION_CODE` | Bypass header `x-introspectioncode` for schema introspection — **only honoured when `NODE_ENV` is `development` or `test`** (see below) |
|
|
204
204
|
| `SOCKETLABS_SERVER_ID`, `SOCKETLABS_SERVER_APIKEY` | SocketLabs auth |
|
|
205
205
|
| `PLATFORM_NAME`, `APP_DOMAIN`, `EMAIL_FROM`, `DEV_TEAM_EMAIL` | Email templating |
|
|
206
206
|
| `STATIC_FOLDER` | Destination for `moveFileStaticDomain` |
|
|
207
|
-
| `NODE_ENV` | `development` enables extra Sentry capture in the error handler |
|
|
207
|
+
| `NODE_ENV` | `development` enables extra Sentry capture in the error handler. Also gates the introspection bypass: `development` and `test` are the only values that let `x-introspectioncode` skip authentication |
|
|
208
208
|
|
|
209
209
|
Each module calls `dotenv.config()` at import time.
|
|
210
210
|
|
|
211
|
+
### Introspection bypass and `NODE_ENV` (6.0.0)
|
|
212
|
+
|
|
213
|
+
`x-introspectioncode` skips authentication in `authenticatedResourceHandler`, `authenticatedAuthorizationHandler` and `authenticatedLogoutHandler`. Up to 5.9.0 it did so under **every** `NODE_ENV`. From 6.0.0 the bypass is refused unless `process.env.NODE_ENV` is exactly `development` or `test` — the check runs before `INTROSPECTION_CODE` is read, so a correct secret and a correct header still fail everywhere else.
|
|
214
|
+
|
|
215
|
+
The gate is an allowlist, not `NODE_ENV !== 'production'`, so unset, empty, `Production`, `prod` and `staging` all refuse. A mislabelled environment loses a development convenience rather than opening authentication.
|
|
216
|
+
|
|
217
|
+
The predicate ships as a public export so consumers can drop their own copy:
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
import { isIntrospectionBypassAllowed } from '@axiumine/koa-utils/lib/isIntrospectionBypassAllowed'
|
|
221
|
+
|
|
222
|
+
if (isIntrospectionBypassAllowed()) {
|
|
223
|
+
// mount the introspection-friendly route
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
211
227
|
## TLS / cookies
|
|
212
228
|
|
|
213
229
|
`tokenOptions` sets `secure: false` by design. Flip it at the reverse proxy (Nginx / Caddy / CloudFront), not in source.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* May the `x-introspectioncode` authentication bypass run in this process at all?
|
|
3
|
+
*
|
|
4
|
+
* True only when `process.env.NODE_ENV` is exactly `'development'` or `'test'`. Every other value
|
|
5
|
+
* — including unset, empty, `'Production'`, `'prod'` and `'staging'` — returns `false`.
|
|
6
|
+
*
|
|
7
|
+
* ⚠️ This is an allowlist, and it must stay one. Do not "simplify" it to
|
|
8
|
+
* `process.env.NODE_ENV !== 'production'`. The two forms differ only on unrecognised values, and
|
|
9
|
+
* that difference is the entire point: the negated form fails *open* on exactly the input most
|
|
10
|
+
* likely to be wrong. An unset or empty `NODE_ENV` is the ordinary failure of a container runtime,
|
|
11
|
+
* and `'Production'` / `'prod'` / `'staging'` are the ordinary failures of a deploy script — under
|
|
12
|
+
* the negated form every one of them enables an authentication bypass in production, silently.
|
|
13
|
+
* Under the allowlist an unrecognised value refuses, so a mislabelled environment loses a
|
|
14
|
+
* development convenience instead of opening authentication.
|
|
15
|
+
*
|
|
16
|
+
* Exported because consumers already maintain their own copy of this predicate: the bypass is only
|
|
17
|
+
* coherent while the library and the app agree on which environments are permitted to use it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isIntrospectionBypassAllowed(): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* May the `x-introspectioncode` authentication bypass run in this process at all?
|
|
3
|
+
*
|
|
4
|
+
* True only when `process.env.NODE_ENV` is exactly `'development'` or `'test'`. Every other value
|
|
5
|
+
* — including unset, empty, `'Production'`, `'prod'` and `'staging'` — returns `false`.
|
|
6
|
+
*
|
|
7
|
+
* ⚠️ This is an allowlist, and it must stay one. Do not "simplify" it to
|
|
8
|
+
* `process.env.NODE_ENV !== 'production'`. The two forms differ only on unrecognised values, and
|
|
9
|
+
* that difference is the entire point: the negated form fails *open* on exactly the input most
|
|
10
|
+
* likely to be wrong. An unset or empty `NODE_ENV` is the ordinary failure of a container runtime,
|
|
11
|
+
* and `'Production'` / `'prod'` / `'staging'` are the ordinary failures of a deploy script — under
|
|
12
|
+
* the negated form every one of them enables an authentication bypass in production, silently.
|
|
13
|
+
* Under the allowlist an unrecognised value refuses, so a mislabelled environment loses a
|
|
14
|
+
* development convenience instead of opening authentication.
|
|
15
|
+
*
|
|
16
|
+
* Exported because consumers already maintain their own copy of this predicate: the bypass is only
|
|
17
|
+
* coherent while the library and the app agree on which environments are permitted to use it.
|
|
18
|
+
*/
|
|
19
|
+
export function isIntrospectionBypassAllowed() {
|
|
20
|
+
const nodeEnv = process.env.NODE_ENV;
|
|
21
|
+
return nodeEnv === 'development' || nodeEnv === 'test';
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=isIntrospectionBypassAllowed.mjs.map
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Constant-time check of the `x-introspectioncode` header against INTROSPECTION_CODE.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Environment-gated first: unless `isIntrospectionBypassAllowed()` says this process runs under
|
|
5
|
+
* `NODE_ENV` `'development'` or `'test'`, this returns `false` before INTROSPECTION_CODE is read
|
|
6
|
+
* at all. A correctly configured secret plus a correct header still fails in production. That
|
|
7
|
+
* gate is an allowlist on purpose — see `isIntrospectionBypassAllowed` for why the negated
|
|
8
|
+
* `NODE_ENV !== 'production'` form is unsafe and must not be substituted here.
|
|
9
|
+
*
|
|
10
|
+
* The gate lives in this function rather than in the three middlewares that call it, so a direct
|
|
11
|
+
* caller of the primitive cannot reach an ungated comparison.
|
|
12
|
+
*
|
|
13
|
+
* Fails closed on the secret too: an unset or empty INTROSPECTION_CODE never matches, whatever the
|
|
14
|
+
* caller sends. The call sites previously compared against `${process.env.INTROSPECTION_CODE}`,
|
|
15
|
+
* which coerces an unset variable to the literal string 'undefined' — a client sending that exact
|
|
16
|
+
* header value satisfied the check with no secret at all.
|
|
8
17
|
*/
|
|
9
18
|
export declare const verifyIntrospectionCode: (headerValue: string | undefined) => boolean;
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import { timingSafeEqual } from 'node:crypto';
|
|
3
|
+
import { isIntrospectionBypassAllowed } from "../../lib/isIntrospectionBypassAllowed.mjs";
|
|
3
4
|
/**
|
|
4
5
|
* Constant-time check of the `x-introspectioncode` header against INTROSPECTION_CODE.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Environment-gated first: unless `isIntrospectionBypassAllowed()` says this process runs under
|
|
8
|
+
* `NODE_ENV` `'development'` or `'test'`, this returns `false` before INTROSPECTION_CODE is read
|
|
9
|
+
* at all. A correctly configured secret plus a correct header still fails in production. That
|
|
10
|
+
* gate is an allowlist on purpose — see `isIntrospectionBypassAllowed` for why the negated
|
|
11
|
+
* `NODE_ENV !== 'production'` form is unsafe and must not be substituted here.
|
|
12
|
+
*
|
|
13
|
+
* The gate lives in this function rather than in the three middlewares that call it, so a direct
|
|
14
|
+
* caller of the primitive cannot reach an ungated comparison.
|
|
15
|
+
*
|
|
16
|
+
* Fails closed on the secret too: an unset or empty INTROSPECTION_CODE never matches, whatever the
|
|
17
|
+
* caller sends. The call sites previously compared against `${process.env.INTROSPECTION_CODE}`,
|
|
18
|
+
* which coerces an unset variable to the literal string 'undefined' — a client sending that exact
|
|
19
|
+
* header value satisfied the check with no secret at all.
|
|
10
20
|
*/
|
|
11
21
|
export const verifyIntrospectionCode = (headerValue) => {
|
|
22
|
+
if (!isIntrospectionBypassAllowed()) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
12
25
|
const code = process.env.INTROSPECTION_CODE;
|
|
13
26
|
if (typeof code !== 'string' || code.length === 0) {
|
|
14
27
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axiumine/koa-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Koa Utils",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -612,6 +612,10 @@
|
|
|
612
612
|
"import": "./dist/lib/ICookies.mjs",
|
|
613
613
|
"types": "./dist/lib/ICookies.d.mts"
|
|
614
614
|
},
|
|
615
|
+
"./lib/isIntrospectionBypassAllowed": {
|
|
616
|
+
"import": "./dist/lib/isIntrospectionBypassAllowed.mjs",
|
|
617
|
+
"types": "./dist/lib/isIntrospectionBypassAllowed.d.mts"
|
|
618
|
+
},
|
|
615
619
|
"./lib/isSessionBlocked": {
|
|
616
620
|
"import": "./dist/lib/isSessionBlocked.mjs",
|
|
617
621
|
"types": "./dist/lib/isSessionBlocked.d.mts"
|