@guren/server 2.14.0 → 2.15.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/dist/{Hash-CzrwKeDp.js → Hash-C8aejmi8.js} +5 -0
- package/dist/agent/AgentApprovalRequested.d.ts +59 -0
- package/dist/agent/approval.d.ts +295 -0
- package/dist/agent/audit-emitter.d.ts +64 -0
- package/dist/agent/audit.d.ts +103 -0
- package/dist/agent/dispatch.d.ts +50 -8
- package/dist/agent/meta-tools.d.ts +62 -0
- package/dist/agent/public.d.ts +33 -0
- package/dist/agent/public.js +2 -0
- package/dist/auth/index.js +1 -1
- package/dist/auth/password/DefaultHasher.d.ts +18 -5
- package/dist/auth/password/PasswordHasher.d.ts +15 -0
- package/dist/auth/password/hash-format.d.ts +19 -0
- package/dist/{auth-BSUc14CD.js → auth-DkYoAPVn.js} +121 -32
- package/dist/broadcasting/index.js +1 -1
- package/dist/{broadcasting-BxU-LIfF.js → broadcasting-BwodCA4q.js} +1 -1
- package/dist/container/bindings.d.ts +19 -0
- package/dist/dispatch-erOS9epZ.js +285 -0
- package/dist/encryption/index.js +2 -2
- package/dist/{encryption-DJtkkhiw.js → encryption-D99Vmls3.js} +4 -1
- package/dist/http/dev-assets.d.ts +16 -0
- package/dist/http/public-assets.d.ts +10 -0
- package/dist/http/request.d.ts +88 -1
- package/dist/http/static-documents.d.ts +31 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +586 -333
- package/dist/internal/request.d.ts +15 -9
- package/dist/internal/request.js +2 -2
- package/dist/logging/channels/DailyFileChannel.d.ts +0 -2
- package/dist/logging/daily-file-path.d.ts +24 -0
- package/dist/logging/index.d.ts +1 -0
- package/dist/logging/index.js +2 -2
- package/dist/{logging-CPaRMuPP.js → logging-B-kngi3q.js} +61 -18
- package/dist/mvc/Controller.d.ts +0 -26
- package/dist/{request-CRVuIiQr.js → request-CVQwpu2J.js} +56 -5
- package/dist/runtime/index.js +90 -14
- package/dist/{vite-manifest-BGfWbPYp.js → vite-manifest-w_RSOvQW.js} +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The names a protocol adapter may add to an application's tool catalogue on
|
|
3
|
+
* its own, and which an application route therefore may not claim (RFC 0016
|
|
4
|
+
* §5.4).
|
|
5
|
+
*
|
|
6
|
+
* This is the one rule, with two readers. `@guren/plugin-mcp` adds
|
|
7
|
+
* `guren.preflight` to the catalogue it serves; `guren check` fails a route
|
|
8
|
+
* whose `.agent()` tool name would collide with it. Restating the string in
|
|
9
|
+
* either place is how the two drift: the check would keep passing a route
|
|
10
|
+
* whose tool the endpoint has already shadowed, and `tools/list` would carry
|
|
11
|
+
* two tools with one name — which an MCP client rejects wholesale, so the
|
|
12
|
+
* collision costs the *entire* catalogue, not the one tool.
|
|
13
|
+
*
|
|
14
|
+
* It lives beside the derivation rather than in the plugin because the check
|
|
15
|
+
* cannot import the plugin (the CLI does not depend on it, and an app that
|
|
16
|
+
* never installs App MCP is still checked), and the plugin must not restate a
|
|
17
|
+
* name the check is enforcing.
|
|
18
|
+
*
|
|
19
|
+
* The list stays deliberately short. Every entry is a name taken away from
|
|
20
|
+
* applications, and the `guren.` prefix is not reserved wholesale for the
|
|
21
|
+
* same reason: reserving a namespace nothing occupies fails routes over a
|
|
22
|
+
* collision that does not exist.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* The preflight companion tool (RFC 0016 §5.4).
|
|
26
|
+
*
|
|
27
|
+
* Preflight cannot be an *argument* of the tool being checked on MCP: a tool
|
|
28
|
+
* advertising an `outputSchema` must answer with `structuredContent`
|
|
29
|
+
* conforming to it unless the result is an error, and a verdict conforms to
|
|
30
|
+
* no route's output. So the verdict needs a tool of its own, with its own
|
|
31
|
+
* output schema — one meta-tool for the whole catalogue, not one companion
|
|
32
|
+
* per tool, which would double the catalogue against §5.5's own
|
|
33
|
+
* catalogue-quality rule.
|
|
34
|
+
*/
|
|
35
|
+
export declare const PREFLIGHT_TOOL_NAME = "guren.preflight";
|
|
36
|
+
/**
|
|
37
|
+
* The approval-status companion tool (RFC 0016 §5.4 item 4).
|
|
38
|
+
*
|
|
39
|
+
* A tool declaring `approval: 'required'` answers its first call with a
|
|
40
|
+
* pending record rather than an execution, and the caller is handed a request
|
|
41
|
+
* id. Something has to be able to say what became of that id, and it cannot be
|
|
42
|
+
* the gated tool itself for the reason preflight cannot be an argument of one:
|
|
43
|
+
* a status is not that route's output, and a tool advertising an `outputSchema`
|
|
44
|
+
* may not answer with a different shape of success.
|
|
45
|
+
*
|
|
46
|
+
* A second meta-tool rather than a mode of the first: `guren.preflight`
|
|
47
|
+
* rehearses a call and answers a verdict, this reads a record and answers its
|
|
48
|
+
* state. Folding both under one name would mean one tool whose output schema
|
|
49
|
+
* is the union of two unrelated shapes, which is the thing a schema is for
|
|
50
|
+
* preventing.
|
|
51
|
+
*/
|
|
52
|
+
export declare const APPROVAL_STATUS_TOOL_NAME = "guren.approval_status";
|
|
53
|
+
/** Every meta-tool name an adapter may occupy. */
|
|
54
|
+
export declare const RESERVED_AGENT_TOOL_NAMES: readonly string[];
|
|
55
|
+
/**
|
|
56
|
+
* Whether a tool name belongs to the framework rather than the application.
|
|
57
|
+
*
|
|
58
|
+
* Case-sensitive, like every other comparison the tool-name grammar makes:
|
|
59
|
+
* MCP tool names are matched literally, so `Guren.Preflight` is a different
|
|
60
|
+
* tool and reserving it would take a name away for nothing.
|
|
61
|
+
*/
|
|
62
|
+
export declare function isReservedAgentToolName(name: string): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The published entry of `@guren/server/agent` (mirrored as
|
|
3
|
+
* `@guren/core/agent`): the half of the agent surface an *out-of-process*
|
|
4
|
+
* dispatcher needs — a browser tab running WebMCP, a CLI, a test harness —
|
|
5
|
+
* as opposed to the half that only makes sense inside a running application.
|
|
6
|
+
*
|
|
7
|
+
* Everything else under `src/agent/` stays internal and is reached through
|
|
8
|
+
* the package index: the audit events, the approval queue, the scope grammar
|
|
9
|
+
* and `deriveAgentTools` itself all import from the application (`Event`, the
|
|
10
|
+
* container, `Router`), which is exactly what a client bundle must not pull
|
|
11
|
+
* in. This module is the one place that promises otherwise, so the promise is
|
|
12
|
+
* stated here rather than left to whoever next adds a re-export:
|
|
13
|
+
*
|
|
14
|
+
* - **Pure Web API.** `Request` / `Response` / `Headers` / `URLSearchParams`
|
|
15
|
+
* and nothing else. No `node:` import, no Bun global, no DOM access — the
|
|
16
|
+
* module must be importable under SSR as well as in a browser. Its two
|
|
17
|
+
* transitive imports (`../internal/route-path`, `../internal/agent-preflight`)
|
|
18
|
+
* are string and regex constants for that reason.
|
|
19
|
+
* - **Types only from `./derive`.** `dispatch.ts` imports `DerivedAgentTool`
|
|
20
|
+
* with `import type`, so the derivation — which reaches `Router` and the
|
|
21
|
+
* authorization middleware — never enters the graph. Re-exporting a *value*
|
|
22
|
+
* from `./derive` here would undo that silently: the bundle would grow the
|
|
23
|
+
* whole route layer and nothing would fail.
|
|
24
|
+
*
|
|
25
|
+
* A consumer holding a `.guren/agents.gen.ts` manifest therefore has
|
|
26
|
+
* everything needed to turn a flat tool call into the HTTP request the route
|
|
27
|
+
* validates, and the route's response back into an MCP tool result — the one
|
|
28
|
+
* dispatch contract (RFC 0016 §3), not a second one written per surface.
|
|
29
|
+
*/
|
|
30
|
+
export { advertisesStructuredOutput, buildToolRequest, describeBuildFailure, mapToolResponse, PREFLIGHT_ARGUMENT, } from './dispatch.js';
|
|
31
|
+
export type { BuildToolRequestOptions, BuiltToolRequest, ToolCallOutcome, ToolRequestBuildFailure, } from './dispatch.js';
|
|
32
|
+
export type { AgentToolInputSource, AgentToolSchema, DerivedAgentTool, DerivedAgentToolAnnotations, DerivedAgentToolExposure, } from './derive.js';
|
|
33
|
+
export type { AgentSurface } from './events.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as mapToolResponse, i as describeBuildFailure, n as advertisesStructuredOutput, r as buildToolRequest, t as PREFLIGHT_ARGUMENT } from "../dispatch-erOS9epZ.js";
|
|
2
|
+
export { PREFLIGHT_ARGUMENT, advertisesStructuredOutput, buildToolRequest, describeBuildFailure, mapToolResponse };
|
package/dist/auth/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as buildTokenUrl, A as verifyOAuthState, B as getApiToken, C as createGoogleOAuthProviderConfig, D as fetchOAuthUserProfile, E as exchangeOAuthCode, F as TokenGuard, G as readBearerToken, H as getUserApiTokens, I as API_TOKEN_KEY, J as tokenCan, K as revokeAllApiTokens, L as MemoryApiTokenStore, O as parseOAuthRedirectUrl, P as AuthManager, Q as SessionGuard, R as createApiToken, S as createGitHubOAuthProviderConfig, T as createOAuthState, V as getApiTokenOrFail, W as parseApiToken, X as tokenCanAny, Y as tokenCanAll, Z as verifyApiToken, _ as OAUTH_SESSION_BINDING_KEY, a as isEmailVerified, at as secureStringCompare, b as buildOAuthRedirectUrl, c as verifyEmailToken, d as completePasswordReset, et as generateId, f as createPasswordResetToken, g as MemoryOAuthStateStore, h as AuthenticatableModel, i as createEmailVerificationToken, it as secureCompare, k as sanitizeOAuthRedirect, l as MemoryPasswordResetStore, lt as NodeHasher, m as verifyPasswordResetToken, n as buildVerificationUrl, nt as hashToken, o as parseVerificationUrl, ot as ModelUserProvider, p as parsePasswordResetUrl, q as revokeApiToken, r as completeEmailVerification, rt as parseTokenUrl, s as requireVerifiedEmail, st as BaseUserProvider, t as MemoryEmailVerificationStore, tt as generateToken, u as buildPasswordResetUrl, ut as ScryptHasher, v as OAuthManager, w as createOAuthManager, x as createDiscordOAuthProviderConfig, y as buildOAuthAuthorizeUrl, z as createBearerTokenMiddleware } from "../auth-DkYoAPVn.js";
|
|
2
2
|
export { API_TOKEN_KEY, AuthManager, AuthenticatableModel, BaseUserProvider, MemoryApiTokenStore, MemoryEmailVerificationStore, MemoryOAuthStateStore, MemoryPasswordResetStore, ModelUserProvider, NodeHasher, OAUTH_SESSION_BINDING_KEY, OAuthManager, ScryptHasher, SessionGuard, TokenGuard, buildOAuthAuthorizeUrl, buildOAuthRedirectUrl, buildPasswordResetUrl, buildTokenUrl, buildVerificationUrl, completeEmailVerification, completePasswordReset, createApiToken, createBearerTokenMiddleware, createDiscordOAuthProviderConfig, createEmailVerificationToken, createGitHubOAuthProviderConfig, createGoogleOAuthProviderConfig, createOAuthManager, createOAuthState, createPasswordResetToken, exchangeOAuthCode, fetchOAuthUserProfile, generateId, generateToken, getApiToken, getApiTokenOrFail, getUserApiTokens, hashToken, isEmailVerified, parseApiToken, parseOAuthRedirectUrl, parsePasswordResetUrl, parseTokenUrl, parseVerificationUrl, readBearerToken, requireVerifiedEmail, revokeAllApiTokens, revokeApiToken, sanitizeOAuthRedirect, secureCompare, secureStringCompare, tokenCan, tokenCanAll, tokenCanAny, verifyApiToken, verifyEmailToken, verifyOAuthState, verifyPasswordResetToken };
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import type { PasswordHasher } from './PasswordHasher.js';
|
|
2
2
|
/**
|
|
3
|
-
* Runtime-detecting password hasher:
|
|
4
|
-
*
|
|
5
|
-
* (e.g. AWS Lambda
|
|
6
|
-
*
|
|
3
|
+
* Runtime-detecting password hasher: hashes with `Bun.password` when running
|
|
4
|
+
* on Bun (Argon2id by default, despite `ScryptHasher`'s name) and with Node's
|
|
5
|
+
* `crypto.scrypt` otherwise (e.g. AWS Lambda or Cloudflare Workers). This is
|
|
6
|
+
* the hasher behind the `Hash` export, and the default for
|
|
7
|
+
* `AuthenticatableModel` and `ModelUserProvider`.
|
|
8
|
+
*
|
|
9
|
+
* **Verification routes on the stored hash, not on the runtime.** The two
|
|
10
|
+
* delegates write different formats, and neither can read the other's, so
|
|
11
|
+
* picking a delegate by runtime alone would 500 on every login for an app
|
|
12
|
+
* whose password column was written elsewhere - a seeder run on Bun against a
|
|
13
|
+
* database a Node deploy then serves. Bun implements `node:crypto`, so a
|
|
14
|
+
* `$scrypt$` hash verifies on either runtime; an Argon2id or bcrypt hash needs
|
|
15
|
+
* `Bun.password` and cannot be read off Bun at all, which this reports as
|
|
16
|
+
* itself rather than as an opaque parse failure.
|
|
7
17
|
*/
|
|
8
18
|
export declare class DefaultHasher implements PasswordHasher {
|
|
9
|
-
private readonly
|
|
19
|
+
private readonly bun;
|
|
20
|
+
private readonly node;
|
|
10
21
|
constructor();
|
|
11
22
|
hash(plain: string): Promise<string>;
|
|
12
23
|
verify(hashed: string, plain: string): Promise<boolean>;
|
|
24
|
+
needsRehash(hashed: string): boolean;
|
|
25
|
+
private delegateFor;
|
|
13
26
|
}
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
export interface PasswordHasher {
|
|
2
2
|
hash(plain: string): Promise<string>;
|
|
3
|
+
/**
|
|
4
|
+
* Checks a plaintext password against a stored hash.
|
|
5
|
+
*
|
|
6
|
+
* **The stored hash comes first.** This order is the inverse of both
|
|
7
|
+
* `Bun.password.verify(plain, hashed)` (which `ScryptHasher` delegates to)
|
|
8
|
+
* and `verifyPassword(plain, hashed)` (exported from this package's
|
|
9
|
+
* `encryption/Hash`), so the two conventions coexist in one codebase.
|
|
10
|
+
*
|
|
11
|
+
* Both parameters are `string`, so a swapped call type-checks. The built-in
|
|
12
|
+
* hashers detect the obvious case at runtime and throw a `TypeError` naming
|
|
13
|
+
* the order; a custom implementation gets no such help.
|
|
14
|
+
*
|
|
15
|
+
* @param hashed - The stored password hash, e.g. from a `passwordHash` column.
|
|
16
|
+
* @param plain - The plaintext password supplied by the request.
|
|
17
|
+
*/
|
|
3
18
|
verify(hashed: string, plain: string): Promise<boolean>;
|
|
4
19
|
needsRehash?(hashed: string): boolean;
|
|
5
20
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** The prefix every hash `NodeHasher` (and `hashPassword()`) writes. */
|
|
2
|
+
export declare const NODE_SCRYPT_PREFIX = "$scrypt$";
|
|
3
|
+
export declare function looksLikePasswordHash(value: string): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Throws when `verify()` was called as `verify(plain, hashed)`.
|
|
6
|
+
*
|
|
7
|
+
* Two-sided on purpose: it fires only when the second argument looks like a
|
|
8
|
+
* hash *and* the first does not. A one-sided "the first argument must look
|
|
9
|
+
* like a hash" precondition would misdiagnose a legitimate non-hash
|
|
10
|
+
* credential column - `passwordHash: 'oauth:...'`, the sentinel this repo
|
|
11
|
+
* documents for OAuth-only accounts - as a caller mistake. Those keep falling
|
|
12
|
+
* through to the implementation, which rejects them as before.
|
|
13
|
+
*
|
|
14
|
+
* Neither argument is included in the message: one of them is a plaintext
|
|
15
|
+
* password, and this throw is reached on a live login attempt.
|
|
16
|
+
*
|
|
17
|
+
* See `PasswordHasher.verify` for why the order is easy to get wrong.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assertVerifyArgumentOrder(hashed: string, plain: string): void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as HttpException } from "./HttpException-BkS3euNG.js";
|
|
2
2
|
import { o as getAppKeyringFromEnv, r as deriveAppKeyring, t as MessageSigner } from "./MessageSigner-Bd25ZJAV.js";
|
|
3
|
+
import { d as verifyPassword, o as needsRehash, r as hashPassword } from "./Hash-C8aejmi8.js";
|
|
3
4
|
import { isExpired, isOptionalExpiryPast } from "./support/expiry.js";
|
|
4
5
|
import { n as getAuthContext } from "./context-DoD0c7J_.js";
|
|
5
|
-
import { d as verifyPassword, o as needsRehash, r as hashPassword } from "./Hash-CzrwKeDp.js";
|
|
6
6
|
import { deleteCookie, getCookie, setCookie } from "hono/cookie";
|
|
7
7
|
import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
8
8
|
import { Model } from "@guren/orm";
|
|
@@ -370,6 +370,49 @@ var RequestAuthContext = class {
|
|
|
370
370
|
await this.guard().logout();
|
|
371
371
|
}
|
|
372
372
|
};
|
|
373
|
+
/**
|
|
374
|
+
* Prefixes of every hash format the built-in hashers produce: Bun's argon2
|
|
375
|
+
* family (`$argon2id$`, `$argon2i$`, `$argon2d$`), bcrypt (`$2a$`, `$2b$`,
|
|
376
|
+
* `$2y$`), and the Node fallback's scrypt.
|
|
377
|
+
*
|
|
378
|
+
* This is a *shape* test, not a validity test. It answers "could this string
|
|
379
|
+
* be a password hash at all", which is all the argument-order check below
|
|
380
|
+
* needs; whether the hash is well-formed stays the implementation's job.
|
|
381
|
+
*
|
|
382
|
+
* Full prefixes rather than the `$argon2` / `$2` stems they share: a password
|
|
383
|
+
* of `$2fast4u` is not bcrypt, and treating it as one turns a correct call
|
|
384
|
+
* against a non-hash credential column into a false accusation.
|
|
385
|
+
*/
|
|
386
|
+
const HASH_PREFIXES = [
|
|
387
|
+
"$argon2id$",
|
|
388
|
+
"$argon2i$",
|
|
389
|
+
"$argon2d$",
|
|
390
|
+
"$2a$",
|
|
391
|
+
"$2b$",
|
|
392
|
+
"$2y$",
|
|
393
|
+
"$scrypt$"
|
|
394
|
+
];
|
|
395
|
+
function looksLikePasswordHash(value) {
|
|
396
|
+
return HASH_PREFIXES.some((prefix) => value.startsWith(prefix));
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Throws when `verify()` was called as `verify(plain, hashed)`.
|
|
400
|
+
*
|
|
401
|
+
* Two-sided on purpose: it fires only when the second argument looks like a
|
|
402
|
+
* hash *and* the first does not. A one-sided "the first argument must look
|
|
403
|
+
* like a hash" precondition would misdiagnose a legitimate non-hash
|
|
404
|
+
* credential column - `passwordHash: 'oauth:...'`, the sentinel this repo
|
|
405
|
+
* documents for OAuth-only accounts - as a caller mistake. Those keep falling
|
|
406
|
+
* through to the implementation, which rejects them as before.
|
|
407
|
+
*
|
|
408
|
+
* Neither argument is included in the message: one of them is a plaintext
|
|
409
|
+
* password, and this throw is reached on a live login attempt.
|
|
410
|
+
*
|
|
411
|
+
* See `PasswordHasher.verify` for why the order is easy to get wrong.
|
|
412
|
+
*/
|
|
413
|
+
function assertVerifyArgumentOrder(hashed, plain) {
|
|
414
|
+
if (!looksLikePasswordHash(hashed) && looksLikePasswordHash(plain)) throw new TypeError("PasswordHasher.verify(hashed, plain) received its arguments in the wrong order: the second argument looks like a password hash and the first does not. Note this order is the inverse of Bun.password.verify(plain, hashed) and of verifyPassword(plain, hashed).");
|
|
415
|
+
}
|
|
373
416
|
//#endregion
|
|
374
417
|
//#region src/auth/password/ScryptHasher.ts
|
|
375
418
|
var ScryptHasher = class {
|
|
@@ -395,6 +438,7 @@ var ScryptHasher = class {
|
|
|
395
438
|
});
|
|
396
439
|
}
|
|
397
440
|
async verify(hashed, plain) {
|
|
441
|
+
assertVerifyArgumentOrder(hashed, plain);
|
|
398
442
|
return Bun.password.verify(plain, hashed);
|
|
399
443
|
}
|
|
400
444
|
needsRehash(hashed) {
|
|
@@ -423,6 +467,77 @@ var ScryptHasher = class {
|
|
|
423
467
|
}
|
|
424
468
|
};
|
|
425
469
|
//#endregion
|
|
470
|
+
//#region src/auth/password/NodeHasher.ts
|
|
471
|
+
/**
|
|
472
|
+
* Node.js-compatible password hasher using crypto.scrypt.
|
|
473
|
+
* Use this instead of ScryptHasher when deploying to non-Bun runtimes (e.g. AWS Lambda).
|
|
474
|
+
*/
|
|
475
|
+
var NodeHasher = class {
|
|
476
|
+
options;
|
|
477
|
+
constructor(options = {}) {
|
|
478
|
+
this.options = {
|
|
479
|
+
cost: options.cost,
|
|
480
|
+
memory: options.memory,
|
|
481
|
+
saltLength: options.saltLength,
|
|
482
|
+
keyLength: options.keyLength
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
async hash(plain) {
|
|
486
|
+
return hashPassword(plain, this.options);
|
|
487
|
+
}
|
|
488
|
+
async verify(hashed, plain) {
|
|
489
|
+
assertVerifyArgumentOrder(hashed, plain);
|
|
490
|
+
return verifyPassword(plain, hashed);
|
|
491
|
+
}
|
|
492
|
+
needsRehash(hashed) {
|
|
493
|
+
return needsRehash(hashed, this.options);
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
//#endregion
|
|
497
|
+
//#region src/auth/password/DefaultHasher.ts
|
|
498
|
+
/**
|
|
499
|
+
* Runtime-detecting password hasher: hashes with `Bun.password` when running
|
|
500
|
+
* on Bun (Argon2id by default, despite `ScryptHasher`'s name) and with Node's
|
|
501
|
+
* `crypto.scrypt` otherwise (e.g. AWS Lambda or Cloudflare Workers). This is
|
|
502
|
+
* the hasher behind the `Hash` export, and the default for
|
|
503
|
+
* `AuthenticatableModel` and `ModelUserProvider`.
|
|
504
|
+
*
|
|
505
|
+
* **Verification routes on the stored hash, not on the runtime.** The two
|
|
506
|
+
* delegates write different formats, and neither can read the other's, so
|
|
507
|
+
* picking a delegate by runtime alone would 500 on every login for an app
|
|
508
|
+
* whose password column was written elsewhere - a seeder run on Bun against a
|
|
509
|
+
* database a Node deploy then serves. Bun implements `node:crypto`, so a
|
|
510
|
+
* `$scrypt$` hash verifies on either runtime; an Argon2id or bcrypt hash needs
|
|
511
|
+
* `Bun.password` and cannot be read off Bun at all, which this reports as
|
|
512
|
+
* itself rather than as an opaque parse failure.
|
|
513
|
+
*/
|
|
514
|
+
var DefaultHasher = class {
|
|
515
|
+
bun;
|
|
516
|
+
node;
|
|
517
|
+
constructor() {
|
|
518
|
+
this.bun = typeof Bun !== "undefined" ? new ScryptHasher() : null;
|
|
519
|
+
this.node = new NodeHasher();
|
|
520
|
+
}
|
|
521
|
+
hash(plain) {
|
|
522
|
+
return (this.bun ?? this.node).hash(plain);
|
|
523
|
+
}
|
|
524
|
+
verify(hashed, plain) {
|
|
525
|
+
return this.delegateFor(hashed).verify(hashed, plain);
|
|
526
|
+
}
|
|
527
|
+
needsRehash(hashed) {
|
|
528
|
+
if (hashed.startsWith("$scrypt$") !== (this.bun === null)) return true;
|
|
529
|
+
return this.delegateFor(hashed).needsRehash(hashed);
|
|
530
|
+
}
|
|
531
|
+
delegateFor(hashed) {
|
|
532
|
+
if (hashed.startsWith("$scrypt$")) return this.node;
|
|
533
|
+
if (!this.bun) {
|
|
534
|
+
if (!looksLikePasswordHash(hashed)) throw new Error("This value is not a password hash in any format the built-in hashers produce, so it cannot be verified. A credential column holding a sentinel for a passwordless account should not reach verify().");
|
|
535
|
+
throw new Error("This password hash was written by Bun.password (Argon2id or bcrypt) and cannot be verified on a runtime without Bun. Hash formats follow the runtime that wrote them, so a column seeded under Bun has to be rehashed before a Node or Workers deploy can read it.");
|
|
536
|
+
}
|
|
537
|
+
return this.bun;
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
//#endregion
|
|
426
541
|
//#region src/auth/providers/UserProvider.ts
|
|
427
542
|
/**
|
|
428
543
|
* Run a user record through the provider's optional `sanitize` before it
|
|
@@ -471,7 +586,7 @@ var ModelUserProvider = class extends BaseUserProvider {
|
|
|
471
586
|
this.usernameColumn = options.usernameColumn ?? "email";
|
|
472
587
|
this.passwordColumn = options.passwordColumn ?? authModel?.resolvePasswordHashField() ?? "passwordHash";
|
|
473
588
|
this.rememberTokenColumn = options.rememberTokenColumn ?? authModel?.resolveRememberTokenField() ?? "rememberToken";
|
|
474
|
-
this.hasher = options.hasher ?? new
|
|
589
|
+
this.hasher = options.hasher ?? new DefaultHasher();
|
|
475
590
|
this.credentialsPasswordField = options.credentialsPasswordField ?? "password";
|
|
476
591
|
}
|
|
477
592
|
cast(record) {
|
|
@@ -497,7 +612,7 @@ var ModelUserProvider = class extends BaseUserProvider {
|
|
|
497
612
|
const plain = credentials[this.credentialsPasswordField];
|
|
498
613
|
if (typeof plain !== "string") return false;
|
|
499
614
|
const hashed = user[this.passwordColumn];
|
|
500
|
-
if (typeof hashed !== "string") {
|
|
615
|
+
if (typeof hashed !== "string" || !looksLikePasswordHash(hashed)) {
|
|
501
616
|
await this.hasher.hash("dummy-timing-equalization");
|
|
502
617
|
return false;
|
|
503
618
|
}
|
|
@@ -1214,7 +1329,7 @@ var AuthManager = class {
|
|
|
1214
1329
|
const defaultOptions = {
|
|
1215
1330
|
usernameColumn: "email",
|
|
1216
1331
|
credentialsPasswordField: "password",
|
|
1217
|
-
hasher: new
|
|
1332
|
+
hasher: new DefaultHasher(),
|
|
1218
1333
|
...options
|
|
1219
1334
|
};
|
|
1220
1335
|
this.registerProvider(providerName, () => new ModelUserProvider(model, defaultOptions));
|
|
@@ -1710,32 +1825,6 @@ function parseOAuthRedirectUrl(url) {
|
|
|
1710
1825
|
return parseTokenUrl(url);
|
|
1711
1826
|
}
|
|
1712
1827
|
//#endregion
|
|
1713
|
-
//#region src/auth/password/NodeHasher.ts
|
|
1714
|
-
/**
|
|
1715
|
-
* Node.js-compatible password hasher using crypto.scrypt.
|
|
1716
|
-
* Use this instead of ScryptHasher when deploying to non-Bun runtimes (e.g. AWS Lambda).
|
|
1717
|
-
*/
|
|
1718
|
-
var NodeHasher = class {
|
|
1719
|
-
options;
|
|
1720
|
-
constructor(options = {}) {
|
|
1721
|
-
this.options = {
|
|
1722
|
-
cost: options.cost,
|
|
1723
|
-
memory: options.memory,
|
|
1724
|
-
saltLength: options.saltLength,
|
|
1725
|
-
keyLength: options.keyLength
|
|
1726
|
-
};
|
|
1727
|
-
}
|
|
1728
|
-
async hash(plain) {
|
|
1729
|
-
return hashPassword(plain, this.options);
|
|
1730
|
-
}
|
|
1731
|
-
async verify(hashed, plain) {
|
|
1732
|
-
return verifyPassword(plain, hashed);
|
|
1733
|
-
}
|
|
1734
|
-
needsRehash(hashed) {
|
|
1735
|
-
return needsRehash(hashed, this.options);
|
|
1736
|
-
}
|
|
1737
|
-
};
|
|
1738
|
-
//#endregion
|
|
1739
1828
|
//#region src/auth/AuthenticatableModel.ts
|
|
1740
1829
|
var AuthenticatableModel = class extends Model {
|
|
1741
1830
|
static createType = void 0;
|
|
@@ -1768,7 +1857,7 @@ var AuthenticatableModel = class extends Model {
|
|
|
1768
1857
|
}
|
|
1769
1858
|
static resolvePasswordHasher() {
|
|
1770
1859
|
if (this.passwordHasher) return this.passwordHasher;
|
|
1771
|
-
const hasher = new
|
|
1860
|
+
const hasher = new DefaultHasher();
|
|
1772
1861
|
this.passwordHasher = hasher;
|
|
1773
1862
|
return hasher;
|
|
1774
1863
|
}
|
|
@@ -2142,4 +2231,4 @@ function requireVerifiedEmail(options = {}) {
|
|
|
2142
2231
|
};
|
|
2143
2232
|
}
|
|
2144
2233
|
//#endregion
|
|
2145
|
-
export {
|
|
2234
|
+
export { buildTokenUrl as $, verifyOAuthState as A, getApiToken as B, createGoogleOAuthProviderConfig as C, fetchOAuthUserProfile as D, exchangeOAuthCode as E, TokenGuard as F, readBearerToken as G, getUserApiTokens as H, API_TOKEN_KEY as I, tokenCan as J, revokeAllApiTokens as K, MemoryApiTokenStore as L, isAppRelativePath as M, normalizeRedirectTarget as N, parseOAuthRedirectUrl as O, AuthManager as P, SessionGuard as Q, createApiToken as R, createGitHubOAuthProviderConfig as S, createOAuthState as T, hasBearerHeader as U, getApiTokenOrFail as V, parseApiToken as W, tokenCanAny as X, tokenCanAll as Y, verifyApiToken as Z, OAUTH_SESSION_BINDING_KEY as _, isEmailVerified as a, secureStringCompare as at, buildOAuthRedirectUrl as b, verifyEmailToken as c, DefaultHasher as ct, completePasswordReset as d, AuthenticationException as dt, generateId as et, createPasswordResetToken as f, MemorySessionStore as ft, MemoryOAuthStateStore as g, AuthenticatableModel as h, createEmailVerificationToken as i, secureCompare as it, hostMatchesAllowlist as j, sanitizeOAuthRedirect as k, MemoryPasswordResetStore as l, NodeHasher as lt, verifyPasswordResetToken as m, getSessionFromContext as mt, buildVerificationUrl as n, hashToken as nt, parseVerificationUrl as o, ModelUserProvider as ot, parsePasswordResetUrl as p, createSessionMiddleware as pt, revokeApiToken as q, completeEmailVerification as r, parseTokenUrl as rt, requireVerifiedEmail as s, BaseUserProvider as st, MemoryEmailVerificationStore as t, generateToken as tt, buildPasswordResetUrl as u, ScryptHasher as ut, OAuthManager as v, createOAuthManager as w, createDiscordOAuthProviderConfig as x, buildOAuthAuthorizeUrl as y, createBearerTokenMiddleware as z };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as setBroadcastManager, c as PresenceChannel, i as getBroadcastManager, l as PrivateChannel, n as BroadcastManager, o as RedisDriver, r as createBroadcastManager, s as MemoryDriver, t as createTypedBroadcaster, u as Channel } from "../broadcasting-
|
|
1
|
+
import { a as setBroadcastManager, c as PresenceChannel, i as getBroadcastManager, l as PrivateChannel, n as BroadcastManager, o as RedisDriver, r as createBroadcastManager, s as MemoryDriver, t as createTypedBroadcaster, u as Channel } from "../broadcasting-BwodCA4q.js";
|
|
2
2
|
export { BroadcastManager, Channel, MemoryDriver, PresenceChannel, PrivateChannel, RedisDriver, createBroadcastManager, createTypedBroadcaster, getBroadcastManager, setBroadcastManager };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as parseRequestPayload } from "./request-
|
|
1
|
+
import { a as parseRequestPayload } from "./request-CVQwpu2J.js";
|
|
2
2
|
import { n as isHotReloadRuntime, t as claimHotDisposable } from "./hot-disposables-WsTX2ySN.js";
|
|
3
3
|
import { c as randomHex } from "./Random-DbIJ22KQ.js";
|
|
4
4
|
//#region src/broadcasting/channels/Channel.ts
|
|
@@ -18,6 +18,7 @@ import type { Scheduler } from '../scheduling/index.js';
|
|
|
18
18
|
import type { Gate } from '../authorization/Gate.js';
|
|
19
19
|
import type { ExceptionHandler } from '../errors/index.js';
|
|
20
20
|
import type { SharedInertiaPropsRegistry } from '../mvc/inertia/shared.js';
|
|
21
|
+
import type { AgentAuditEmitter } from '../agent/audit-emitter.js';
|
|
21
22
|
/**
|
|
22
23
|
* Type-safe service binding map.
|
|
23
24
|
*
|
|
@@ -51,5 +52,23 @@ export interface ServiceBindings {
|
|
|
51
52
|
gate: Gate;
|
|
52
53
|
/** Bound lazily on the first `shareInertiaProps(fn, container)` call. */
|
|
53
54
|
'inertia.sharedProps': SharedInertiaPropsRegistry;
|
|
55
|
+
/**
|
|
56
|
+
* How an agent surface records what it did (RFC 0016 §5.2). Bound by
|
|
57
|
+
* `@guren/plugin-mcp` at boot, and absent when no MCP plugin is registered
|
|
58
|
+
* — the key is declared here, where every other service name is, so that a
|
|
59
|
+
* surface resolving it and the plugin binding it spell one string.
|
|
60
|
+
*
|
|
61
|
+
* The binding is the *emitter*, not the sink: a second caller that resolved
|
|
62
|
+
* a sink would have to build its own emitter around it, and the two would
|
|
63
|
+
* then differ on the questions the emitter answers — whether a sink failure
|
|
64
|
+
* warns, whether the events are emitted beside it. One emitter per
|
|
65
|
+
* application means every surface's records reach the same place the same
|
|
66
|
+
* way.
|
|
67
|
+
*
|
|
68
|
+
* An interface key cannot be a constant, so the *runtime* spelling of this
|
|
69
|
+
* name lives once in `AGENT_AUDIT_BINDING`, which both the writing and the
|
|
70
|
+
* reading package import. Rename here and there together.
|
|
71
|
+
*/
|
|
72
|
+
'agent.audit': AgentAuditEmitter;
|
|
54
73
|
'exception.handler': ExceptionHandler;
|
|
55
74
|
}
|