@steve31415/baselib 3.0.1 → 3.0.2

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { OAuth2Client } from 'google-auth-library';
2
- import type { Logger } from './log-core.js';
2
+ import { type Logger } from './log-core.js';
3
3
  /** The fleet coding agent's service-account email, read from AGENT_SA — set at
4
4
  * deploy time by each service (SECURITY.md: agents have full access, so
5
5
  * grantAllows always admits this identity). Env-driven rather than a baked-in
@@ -45,6 +45,10 @@ export interface ResolvedCaller {
45
45
  error: string;
46
46
  };
47
47
  }
48
+ /** `message` with every occurrence of `token` — and of each of its
49
+ * dot-separated segments of 8+ chars, since some verifier messages quote a
50
+ * single segment — replaced by `<token>`, then truncated. */
51
+ export declare function redactToken(message: string, token: string): string;
48
52
  /** Resolve and authorize an s2s caller from a request's Authorization header.
49
53
  * Shared by s2sAuth() and auth.ts's requireIdentity(). */
50
54
  export declare function resolveS2sCaller(opts: S2sOptions & {
package/dist/s2s.js CHANGED
@@ -14,7 +14,9 @@
14
14
  // allowed (SECURITY.md: agents have full access).
15
15
  import { createMiddleware } from 'hono/factory';
16
16
  import { OAuth2Client } from 'google-auth-library';
17
+ import { createHash } from 'node:crypto';
17
18
  import { authMode } from './config.js';
19
+ import { truncate } from './log-core.js';
18
20
  /** The fleet coding agent's service-account email, read from AGENT_SA — set at
19
21
  * deploy time by each service (SECURITY.md: agents have full access, so
20
22
  * grantAllows always admits this identity). Env-driven rather than a baked-in
@@ -60,6 +62,16 @@ export class RateLimiter {
60
62
  return w.count <= this.perMinute;
61
63
  }
62
64
  }
65
+ /** `message` with every occurrence of `token` — and of each of its
66
+ * dot-separated segments of 8+ chars, since some verifier messages quote a
67
+ * single segment — replaced by `<token>`, then truncated. */
68
+ export function redactToken(message, token) {
69
+ const parts = [token, ...token.split('.')].filter((p) => p.length >= 8);
70
+ let out = message;
71
+ for (const p of parts)
72
+ out = out.split(p).join('<token>');
73
+ return truncate(out, 300);
74
+ }
63
75
  /** Resolve and authorize an s2s caller from a request's Authorization header.
64
76
  * Shared by s2sAuth() and auth.ts's requireIdentity(). */
65
77
  export async function resolveS2sCaller(opts, headers, method, path) {
@@ -83,7 +95,17 @@ export async function resolveS2sCaller(opts, headers, method, path) {
83
95
  email = payload.email;
84
96
  }
85
97
  catch (err) {
86
- opts.logger?.warn('s2s token verification failed', { error: err, path });
98
+ // google-auth-library quotes the presented token in its error messages
99
+ // ("Wrong number of segments in token: <jwt>", "Invalid token signature:
100
+ // <jwt>"), so the error is never logged as-is: the token's shape and a
101
+ // redacted message only (PW LESSONS 2026-09-02 — log the shape, never
102
+ // the credential). Found by Mirror2's device-key design review.
103
+ opts.logger?.warn('s2s token verification failed', {
104
+ path,
105
+ reason: redactToken(err instanceof Error ? err.message : String(err), m[1]),
106
+ tokenLength: m[1].length,
107
+ tokenHashPrefix: createHash('sha256').update(m[1]).digest('hex').slice(0, 8),
108
+ });
87
109
  return { failure: { status: 401, error: 'invalid token' } };
88
110
  }
89
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve31415/baselib",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Plasticine new-world shared platform library: logging, auth, service-to-service auth, db, HTTP, sync, app updates",
5
5
  "type": "module",
6
6
  "license": "MIT",