@steve31415/baselib 3.35.0 → 3.36.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/s2s.d.ts +6 -2
- package/dist/s2s.js +11 -0
- package/package.json +1 -1
package/dist/s2s.d.ts
CHANGED
|
@@ -7,8 +7,12 @@ import { type Logger } from './log-core.js';
|
|
|
7
7
|
* disables the always-allow rule (fail closed). */
|
|
8
8
|
export declare function codingAgentSa(): string | undefined;
|
|
9
9
|
/** caller service-account email → allowed "METHOD /path" patterns.
|
|
10
|
-
* Patterns: exact ("GET /api/whoami"), trailing wildcard ("POST /api/admin/*"
|
|
11
|
-
*
|
|
10
|
+
* Patterns: exact ("GET /api/whoami"), trailing wildcard ("POST /api/admin/*",
|
|
11
|
+
* a prefix: the bare path and everything under it), a single-segment
|
|
12
|
+
* wildcard anywhere else ("GET /api/tasks/*\/card": exactly one non-empty
|
|
13
|
+
* segment in that position, so one task-scoped method can be granted without
|
|
14
|
+
* the whole prefix — 2026-10-12, Radar's grant on Coder's card and decide
|
|
15
|
+
* routes), or "*" for everything. */
|
|
12
16
|
export type Grants = Record<string, string[]>;
|
|
13
17
|
export interface ServiceCaller {
|
|
14
18
|
type: 's2s';
|
package/dist/s2s.js
CHANGED
|
@@ -40,9 +40,20 @@ export function grantAllows(grants, email, method, path) {
|
|
|
40
40
|
const prefix = p.slice(0, -1); // keep the trailing slash
|
|
41
41
|
return want.startsWith(prefix) || want === p.slice(0, -2);
|
|
42
42
|
}
|
|
43
|
+
if (p.includes('/*/'))
|
|
44
|
+
return segmentsMatch(p, want);
|
|
43
45
|
return want === p;
|
|
44
46
|
});
|
|
45
47
|
}
|
|
48
|
+
/** "METHOD /a/*\/b" against "METHOD /a/x/b": the same number of segments,
|
|
49
|
+
* each equal or a `*` standing for exactly one non-empty segment. */
|
|
50
|
+
function segmentsMatch(pattern, want) {
|
|
51
|
+
const ps = pattern.split('/');
|
|
52
|
+
const ws = want.split('/');
|
|
53
|
+
if (ps.length !== ws.length)
|
|
54
|
+
return false;
|
|
55
|
+
return ps.every((seg, i) => (seg === '*' ? ws[i].length > 0 : seg === ws[i]));
|
|
56
|
+
}
|
|
46
57
|
// Fixed-window per-identity rate limiter — a sanity check against runaway
|
|
47
58
|
// loops and mischief, not a precision tool (per-instance state only).
|
|
48
59
|
export class RateLimiter {
|
package/package.json
CHANGED