@wildo-ai/saas-workers-node-lib 1.1.9 → 1.1.11
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/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.d.ts.map +1 -1
- package/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.js +10 -4
- package/dist/esm/runtime/middlewares/worker-jwt-verifier.middleware.js.map +1 -1
- package/dist/esm/runtime/services/define-worker-init.d.ts +4 -2
- package/dist/esm/runtime/services/define-worker-init.d.ts.map +1 -1
- package/dist/esm/runtime/services/define-worker-init.js.map +1 -1
- package/dist/esm/runtime/services/read-worker-bootstrap-env.d.ts.map +1 -1
- package/dist/esm/runtime/services/read-worker-bootstrap-env.js +3 -0
- package/dist/esm/runtime/services/read-worker-bootstrap-env.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/runtime/middlewares/__tests__/worker-jwt-verifier.rotation-cutoff.middleware.test.ts +15 -1
- package/src/runtime/middlewares/worker-jwt-verifier.middleware.ts +10 -3
- package/src/runtime/services/define-worker-init.ts +4 -2
- package/src/runtime/services/read-worker-bootstrap-env.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildo-ai/saas-workers-node-lib",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "Node worker runtime host boundary for Wildo SaaS applications",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Wildo AI",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"test:watch": "vitest"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@wildo-ai/platform-config-lib": "1.1.
|
|
34
|
-
"@wildo-ai/platform-core-shared": "1.1.
|
|
35
|
-
"@wildo-ai/saas-backend-lib": "1.1.
|
|
36
|
-
"@wildo-ai/saas-models": "1.1.
|
|
33
|
+
"@wildo-ai/platform-config-lib": "1.1.11",
|
|
34
|
+
"@wildo-ai/platform-core-shared": "1.1.11",
|
|
35
|
+
"@wildo-ai/saas-backend-lib": "1.1.11",
|
|
36
|
+
"@wildo-ai/saas-models": "1.1.11",
|
|
37
37
|
"express": "^5.1.0",
|
|
38
38
|
"helmet": "^8.1.0",
|
|
39
39
|
"jsonwebtoken": "^9.0.2",
|
package/src/runtime/middlewares/__tests__/worker-jwt-verifier.rotation-cutoff.middleware.test.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { generateKeyPairSync } from 'node:crypto';
|
|
|
3
3
|
import jwt from 'jsonwebtoken';
|
|
4
4
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
5
|
|
|
6
|
+
import { CryptoKey_Purpose, singleJwsTypeOf } from '@wildo-ai/saas-models';
|
|
6
7
|
import { createWorkerJwtVerifierMiddleware } from '../worker-jwt-verifier.middleware';
|
|
7
8
|
|
|
8
9
|
function generateSigningPair(): { readonly privateKey: string; readonly publicKey: string } {
|
|
@@ -13,9 +14,10 @@ function generateSigningPair(): { readonly privateKey: string; readonly publicKe
|
|
|
13
14
|
});
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
function signWorkerToken(privateKey: string): string {
|
|
17
|
+
function signWorkerToken(privateKey: string, typ: string = singleJwsTypeOf(CryptoKey_Purpose.APPLICATION_WORKER_REQUEST)): string {
|
|
17
18
|
return jwt.sign({ sub: 'worker-caller' }, privateKey, {
|
|
18
19
|
algorithm: 'ES256',
|
|
20
|
+
header: { alg: 'ES256', typ },
|
|
19
21
|
issuer: 'wildo-application',
|
|
20
22
|
audience: 'APPLICATION_WORKER',
|
|
21
23
|
expiresIn: '5m',
|
|
@@ -59,4 +61,16 @@ describe('worker JWT rotated-key retirement', () => {
|
|
|
59
61
|
expect(refused.response.status).toHaveBeenCalledWith(401);
|
|
60
62
|
expect(refused.response.json).toHaveBeenCalledWith({ error: 'invalid_jwt' });
|
|
61
63
|
});
|
|
64
|
+
|
|
65
|
+
// #2892 — mutation: drop the typ check → a token another of the application's keys signed for another use (same
|
|
66
|
+
// issuer, same audience forged) is admitted by a worker holding only the worker-request public key.
|
|
67
|
+
it('refuses a token whose type is not the worker-request type, even under the trusted key', async () => {
|
|
68
|
+
const { privateKey, publicKey } = generateSigningPair();
|
|
69
|
+
const middleware = createWorkerJwtVerifierMiddleware({ getCurrentPublicKey: () => publicKey });
|
|
70
|
+
const { response } = responseDouble();
|
|
71
|
+
const next = vi.fn();
|
|
72
|
+
await middleware({ headers: { authorization: `Bearer ${signWorkerToken(privateKey, 'wildo-access+jwt')}` } } as never, response as never, next);
|
|
73
|
+
expect(next).not.toHaveBeenCalled();
|
|
74
|
+
expect(response.status).toHaveBeenCalledWith(401);
|
|
75
|
+
});
|
|
62
76
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Request, RequestHandler, Response, NextFunction } from 'express';
|
|
2
2
|
import jwt from 'jsonwebtoken';
|
|
3
|
-
import {
|
|
3
|
+
import { JwtVerifyOptions } from '@wildo-ai/saas-backend-lib';
|
|
4
|
+
import { CryptoKey_Purpose } from '@wildo-ai/saas-models';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Per-request claims attached to the express `Request` object after the
|
|
@@ -55,7 +56,8 @@ export interface WorkerJwtVerifierFactoryInput {
|
|
|
55
56
|
export function createWorkerJwtVerifierMiddleware(
|
|
56
57
|
input: WorkerJwtVerifierFactoryInput,
|
|
57
58
|
): RequestHandler {
|
|
58
|
-
|
|
59
|
+
// The worker-request key signs nothing else, and its tokens carry their purpose's own type (#2892).
|
|
60
|
+
const { expectedTyp, ...verifyOptions } = JwtVerifyOptions[CryptoKey_Purpose.APPLICATION_WORKER_REQUEST];
|
|
59
61
|
|
|
60
62
|
return async (req: Request, res: Response, next: NextFunction): Promise<void> => {
|
|
61
63
|
const authHeader = req.headers.authorization ?? req.headers.Authorization;
|
|
@@ -79,7 +81,7 @@ export function createWorkerJwtVerifierMiddleware(
|
|
|
79
81
|
|
|
80
82
|
for (const candidate of candidates) {
|
|
81
83
|
try {
|
|
82
|
-
const decoded = await verifyOnce(token, candidate.publicKey, verifyOptions);
|
|
84
|
+
const decoded = await verifyOnce(token, candidate.publicKey, verifyOptions, expectedTyp);
|
|
83
85
|
req.workerJwt = decoded;
|
|
84
86
|
next();
|
|
85
87
|
return;
|
|
@@ -95,6 +97,7 @@ function verifyOnce(
|
|
|
95
97
|
token: string,
|
|
96
98
|
publicKey: string,
|
|
97
99
|
verifyOptions: jwt.VerifyOptions,
|
|
100
|
+
expectedTyp: string | undefined,
|
|
98
101
|
): Promise<WorkerVerifiedJwtPayload> {
|
|
99
102
|
return new Promise((resolve, reject) => {
|
|
100
103
|
jwt.verify(token, publicKey, verifyOptions, (err, decoded) => {
|
|
@@ -102,6 +105,10 @@ function verifyOnce(
|
|
|
102
105
|
reject(err);
|
|
103
106
|
return;
|
|
104
107
|
}
|
|
108
|
+
if (expectedTyp !== undefined && jwt.decode(token, { complete: true })?.header?.typ !== expectedTyp) {
|
|
109
|
+
reject(new Error('jwt_typ_invalid'));
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
105
112
|
if (!decoded || typeof decoded === 'string') {
|
|
106
113
|
reject(new Error('jwt_payload_not_object'));
|
|
107
114
|
return;
|
|
@@ -69,8 +69,10 @@ export interface WorkerInitializationConfig {
|
|
|
69
69
|
providerRuntime?: ProviderRuntimeArtifact | WorkerProviderRuntimeArtifact;
|
|
70
70
|
/**
|
|
71
71
|
* Cadence (ms) at which the worker re-polls apps-manager for the
|
|
72
|
-
* trusted `APPLICATION_WORKER_REQUEST` public key. JWKS-style refresh
|
|
73
|
-
*
|
|
72
|
+
* trusted `APPLICATION_WORKER_REQUEST` public key. JWKS-style refresh:
|
|
73
|
+
* the request verifier reads the key fetched by the latest poll, so a
|
|
74
|
+
* rotated signing key is accepted without a worker restart. A failed
|
|
75
|
+
* poll keeps the previous key; omitted or `<= 0` disables re-polling.
|
|
74
76
|
*/
|
|
75
77
|
publicKeyRefreshIntervalMs?: number;
|
|
76
78
|
/**
|
|
@@ -67,6 +67,9 @@ export function readWorkerBootstrapEnv(
|
|
|
67
67
|
ApplicationWorkerBootstrapEnvKey.PLATFORM_APPS_MANAGER_URL,
|
|
68
68
|
);
|
|
69
69
|
const applicationEnv = requireKey(ApplicationWorkerBootstrapEnvKey.APPLICATION_ENV);
|
|
70
|
+
// #2921 — required: the worker verifies every bootstrap answer against these keys. Read again (and parsed) by the
|
|
71
|
+
// bootstrap client; required here so a missing value is named with the other missing variables.
|
|
72
|
+
requireKey(ApplicationWorkerBootstrapEnvKey.PLATFORM_APPS_MANAGER_RESPONSE_VERIFICATION_KEYS);
|
|
70
73
|
|
|
71
74
|
if (missingKeys.length > 0) {
|
|
72
75
|
throw new Error(
|