instar 1.3.1997 → 1.3.1999
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/core/AgentLinks.d.ts +70 -0
- package/dist/core/AgentLinks.d.ts.map +1 -0
- package/dist/core/AgentLinks.js +206 -0
- package/dist/core/AgentLinks.js.map +1 -0
- package/dist/core/safeFileId.d.ts +18 -0
- package/dist/core/safeFileId.d.ts.map +1 -0
- package/dist/core/safeFileId.js +25 -0
- package/dist/core/safeFileId.js.map +1 -0
- package/dist/core/types.d.ts +8 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/data/standards-guard-index.json +1 -1
- package/dist/data/standards-guard-index.meta.json +2 -2
- package/dist/data/standards-registry.meta.json +1 -1
- package/dist/messaging/MessageRouter.d.ts +1 -1
- package/dist/messaging/MessageRouter.d.ts.map +1 -1
- package/dist/messaging/MessageRouter.js +6 -0
- package/dist/messaging/MessageRouter.js.map +1 -1
- package/dist/messaging/MessageStore.d.ts +4 -0
- package/dist/messaging/MessageStore.d.ts.map +1 -1
- package/dist/messaging/MessageStore.js +37 -11
- package/dist/messaging/MessageStore.js.map +1 -1
- package/dist/native/InstarWedgeCanary.app/Contents/MacOS/InstarWedgeCanary +0 -0
- package/dist/native/instar-desktop-host +0 -0
- package/dist/server/AgentServer.d.ts.map +1 -1
- package/dist/server/AgentServer.js +20 -0
- package/dist/server/AgentServer.js.map +1 -1
- package/dist/server/agentLinkRoutes.d.ts +20 -0
- package/dist/server/agentLinkRoutes.d.ts.map +1 -0
- package/dist/server/agentLinkRoutes.js +48 -0
- package/dist/server/agentLinkRoutes.js.map +1 -0
- package/dist/server/mobilePairingRoutes.d.ts +2 -0
- package/dist/server/mobilePairingRoutes.d.ts.map +1 -1
- package/dist/server/mobilePairingRoutes.js +49 -0
- package/dist/server/mobilePairingRoutes.js.map +1 -1
- package/dist/threadline/ThreadLog.d.ts +2 -1
- package/dist/threadline/ThreadLog.d.ts.map +1 -1
- package/dist/threadline/ThreadLog.js +15 -5
- package/dist/threadline/ThreadLog.js.map +1 -1
- package/dist/threadline/recordThreadMessage.js +1 -1
- package/package.json +1 -1
- package/src/data/awareness/agent-links.md +9 -0
- package/src/data/builtin-manifest.json +3 -3
- package/src/data/feature-ladders.json +2 -1
- package/src/data/standards-guard-index.json +1 -1
- package/src/data/standards-guard-index.meta.json +2 -2
- package/src/data/standards-registry.meta.json +1 -1
- package/upgrades/1.3.1998.md +30 -0
- package/upgrades/1.3.1999.md +25 -0
- package/upgrades/side-effects/permanent-agent-links.md +114 -0
- package/upgrades/side-effects/store-id-plain-file-name.md +44 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { readIdentityKeyFile } from '../identity/IdentityKeyFile.js';
|
|
2
|
+
export declare const AGENT_LINK_WEB_BASE = "https://instar.sh/a#";
|
|
3
|
+
export declare const AGENT_LINK_APP_BASE = "instar://a#";
|
|
4
|
+
export declare const PROOF_DOMAIN = "instar-agent-link-proof-v1";
|
|
5
|
+
export type AgentLinkTarget = 'home' | 'doc' | 'conversation';
|
|
6
|
+
export interface AgentLink {
|
|
7
|
+
id: string;
|
|
8
|
+
target: AgentLinkTarget;
|
|
9
|
+
ref: string | null;
|
|
10
|
+
comment: string | null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A safe upper bound on a valid fragment, computed from the grammar: the longest target name
|
|
14
|
+
* with `c` (which the grammar never allows together), and `c` with every ':' encoded as '%3A'.
|
|
15
|
+
*/
|
|
16
|
+
export declare const MAX_FRAGMENT: number;
|
|
17
|
+
/**
|
|
18
|
+
* Parse a v1 fragment (with or without '#'). Returns null for anything that is not a valid v1
|
|
19
|
+
* link: unknown or duplicate keys, a field the target does not take, a field failing its pattern,
|
|
20
|
+
* or a '%' anywhere except '%3A' inside `r` or `c`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseAgentLink(fragment: unknown): AgentLink | null;
|
|
23
|
+
/** The canonical fragment for a valid link, built from typed values in a fixed order. */
|
|
24
|
+
export declare function canonicalFragment(link: AgentLink): string;
|
|
25
|
+
export type BuildLinkResult = {
|
|
26
|
+
ok: true;
|
|
27
|
+
url: string;
|
|
28
|
+
appUrl: string;
|
|
29
|
+
link: AgentLink;
|
|
30
|
+
} | {
|
|
31
|
+
ok: false;
|
|
32
|
+
error: 'bad-target';
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Build a link for this agent. `comment` is included only when the caller passes it (a comment
|
|
36
|
+
* key discloses its author's person key). Returns a reference only: no share, grant or pairing.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildAgentLink(canonicalId: string, input: {
|
|
39
|
+
target?: unknown;
|
|
40
|
+
ref?: unknown;
|
|
41
|
+
comment?: unknown;
|
|
42
|
+
}): BuildLinkResult;
|
|
43
|
+
export type LinkIdentity = {
|
|
44
|
+
ok: true;
|
|
45
|
+
canonicalId: string;
|
|
46
|
+
publicKey: Buffer;
|
|
47
|
+
privateKey: Buffer;
|
|
48
|
+
file: string;
|
|
49
|
+
} | {
|
|
50
|
+
ok: false;
|
|
51
|
+
error: 'no-agent-identity' | 'identity-key-locked' | 'identity-unreadable' | 'identity-split';
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* The identity a link names (spec §2a). Strict: when `<stateDir>/identity.json` exists it alone
|
|
55
|
+
* decides (unusable → identity-unreadable, encrypted → identity-key-locked, no fall-through); the
|
|
56
|
+
* Threadline legacy file is used only when it is absent; both readable with different keys →
|
|
57
|
+
* identity-split. The id is computed from the public key, never read from a stored field.
|
|
58
|
+
*/
|
|
59
|
+
export declare function readLinkIdentity(stateDir: string, deps?: {
|
|
60
|
+
read?: typeof readIdentityKeyFile;
|
|
61
|
+
}): LinkIdentity;
|
|
62
|
+
/** A nonce is exactly 32 bytes as unpadded base64url; any other spelling is refused. */
|
|
63
|
+
export declare function parseNonce(raw: unknown): string | null;
|
|
64
|
+
/** The exact bytes the identity key signs (spec §2a). The fixed first line is domain separation. */
|
|
65
|
+
export declare function proofTranscript(canonicalId: string, deviceId: string, host: string, nonce: string): Buffer;
|
|
66
|
+
/** Sign a proof transcript with the raw 32-byte Ed25519 private key. */
|
|
67
|
+
export declare function signProof(privateKey: Buffer, transcript: Buffer): Buffer;
|
|
68
|
+
/** Verify a proof (used by tests, and the same check the app makes). */
|
|
69
|
+
export declare function verifyProof(publicKey: Buffer, transcript: Buffer, signature: Buffer): boolean;
|
|
70
|
+
//# sourceMappingURL=AgentLinks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentLinks.d.ts","sourceRoot":"","sources":["../../src/core/AgentLinks.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAGrE,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAC1D,eAAO,MAAM,mBAAmB,gBAAgB,CAAC;AACjD,eAAO,MAAM,YAAY,+BAA+B,CAAC;AAEzD,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,KAAK,GAAG,cAAc,CAAC;AAE9D,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,eAAe,CAAC;IACxB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAUD;;;GAGG;AACH,eAAO,MAAM,YAAY,QAA2D,CAAC;AAarF;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CA6BlE;AAED,yFAAyF;AACzF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAKzD;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GA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0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Permanent agent links (docs/specs/permanent-agent-links.md).
|
|
3
|
+
*
|
|
4
|
+
* A link names the agent by its canonical id (SHA-256 over its Ed25519 public key) and a page,
|
|
5
|
+
* never a machine or an address:
|
|
6
|
+
*
|
|
7
|
+
* https://instar.sh/a#v=1&i=<64 hex>&t=home|doc|conversation[&r=<ref>][&c=<comment key>]
|
|
8
|
+
*
|
|
9
|
+
* This module holds the pure parts: the v1 grammar (one parser, shared accept/reject vectors with
|
|
10
|
+
* the site's `a.js` and the app), the link builder, the strict identity read the identity route
|
|
11
|
+
* uses, and the possession-proof transcript. It never mints, repairs or rewrites an identity.
|
|
12
|
+
*/
|
|
13
|
+
import crypto from 'node:crypto';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import { readIdentityKeyFile } from '../identity/IdentityKeyFile.js';
|
|
16
|
+
import { computeCanonicalId } from '../identity/types.js';
|
|
17
|
+
export const AGENT_LINK_WEB_BASE = 'https://instar.sh/a#';
|
|
18
|
+
export const AGENT_LINK_APP_BASE = 'instar://a#';
|
|
19
|
+
export const PROOF_DOMAIN = 'instar-agent-link-proof-v1';
|
|
20
|
+
const ID_RE = /^[0-9a-f]{64}$/;
|
|
21
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
22
|
+
const TG_RE = /^tg:[1-9][0-9]{0,15}$/;
|
|
23
|
+
/** The server's comment-key pattern (src/documents/rows.ts isCommentKey). */
|
|
24
|
+
const COMMENT_RE = /^[A-Za-z0-9._:-]{1,200}:[0-9a-f-]{36}$/;
|
|
25
|
+
const FIELDS = { home: [], doc: ['r', 'c'], conversation: ['r'] };
|
|
26
|
+
const KEYS = ['v', 'i', 't', 'r', 'c'];
|
|
27
|
+
/**
|
|
28
|
+
* A safe upper bound on a valid fragment, computed from the grammar: the longest target name
|
|
29
|
+
* with `c` (which the grammar never allows together), and `c` with every ':' encoded as '%3A'.
|
|
30
|
+
*/
|
|
31
|
+
export const MAX_FRAGMENT = 'v=1&i=&t=conversation&r=&c='.length + 64 + 36 + 3 * 237;
|
|
32
|
+
function isTgRef(ref) {
|
|
33
|
+
return TG_RE.test(ref) && Number(ref.slice(3)) <= Number.MAX_SAFE_INTEGER;
|
|
34
|
+
}
|
|
35
|
+
function validRef(target, ref) {
|
|
36
|
+
if (target === 'home')
|
|
37
|
+
return ref === null;
|
|
38
|
+
if (ref === null)
|
|
39
|
+
return false;
|
|
40
|
+
if (target === 'doc')
|
|
41
|
+
return UUID_RE.test(ref);
|
|
42
|
+
return UUID_RE.test(ref) || isTgRef(ref);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Parse a v1 fragment (with or without '#'). Returns null for anything that is not a valid v1
|
|
46
|
+
* link: unknown or duplicate keys, a field the target does not take, a field failing its pattern,
|
|
47
|
+
* or a '%' anywhere except '%3A' inside `r` or `c`.
|
|
48
|
+
*/
|
|
49
|
+
export function parseAgentLink(fragment) {
|
|
50
|
+
if (typeof fragment !== 'string')
|
|
51
|
+
return null;
|
|
52
|
+
const raw = fragment.replace(/^#/, '');
|
|
53
|
+
if (!raw || raw.length > MAX_FRAGMENT)
|
|
54
|
+
return null;
|
|
55
|
+
const q = new Map();
|
|
56
|
+
for (const kv of raw.split('&')) {
|
|
57
|
+
const i = kv.indexOf('=');
|
|
58
|
+
if (i <= 0)
|
|
59
|
+
return null;
|
|
60
|
+
const k = kv.slice(0, i);
|
|
61
|
+
if (!KEYS.includes(k) || q.has(k))
|
|
62
|
+
return null;
|
|
63
|
+
let v = kv.slice(i + 1);
|
|
64
|
+
if (v.includes('%')) {
|
|
65
|
+
if ((k !== 'c' && k !== 'r') || /%(?!3[aA])/.test(v))
|
|
66
|
+
return null;
|
|
67
|
+
v = v.replace(/%3[aA]/g, ':');
|
|
68
|
+
}
|
|
69
|
+
q.set(k, v);
|
|
70
|
+
}
|
|
71
|
+
if (q.get('v') !== '1')
|
|
72
|
+
return null;
|
|
73
|
+
const id = q.get('i');
|
|
74
|
+
const target = q.get('t');
|
|
75
|
+
if (!id || !ID_RE.test(id))
|
|
76
|
+
return null;
|
|
77
|
+
if (!target || !Object.prototype.hasOwnProperty.call(FIELDS, target))
|
|
78
|
+
return null;
|
|
79
|
+
const t = target;
|
|
80
|
+
for (const k of q.keys())
|
|
81
|
+
if (!['v', 'i', 't'].includes(k) && !FIELDS[t].includes(k))
|
|
82
|
+
return null;
|
|
83
|
+
const ref = q.get('r') ?? null;
|
|
84
|
+
const comment = q.get('c') ?? null;
|
|
85
|
+
if (!validRef(t, ref))
|
|
86
|
+
return null;
|
|
87
|
+
if (comment !== null && !COMMENT_RE.test(comment))
|
|
88
|
+
return null;
|
|
89
|
+
return { id, target: t, ref, comment };
|
|
90
|
+
}
|
|
91
|
+
/** The canonical fragment for a valid link, built from typed values in a fixed order. */
|
|
92
|
+
export function canonicalFragment(link) {
|
|
93
|
+
let f = `v=1&i=${link.id}&t=${link.target}`;
|
|
94
|
+
if (link.ref !== null)
|
|
95
|
+
f += `&r=${link.ref}`;
|
|
96
|
+
if (link.comment !== null)
|
|
97
|
+
f += `&c=${link.comment.replace(/:/g, '%3A')}`;
|
|
98
|
+
return f;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Build a link for this agent. `comment` is included only when the caller passes it (a comment
|
|
102
|
+
* key discloses its author's person key). Returns a reference only: no share, grant or pairing.
|
|
103
|
+
*/
|
|
104
|
+
export function buildAgentLink(canonicalId, input) {
|
|
105
|
+
const target = input.target;
|
|
106
|
+
if (target !== 'home' && target !== 'doc' && target !== 'conversation')
|
|
107
|
+
return { ok: false, error: 'bad-target' };
|
|
108
|
+
let ref = null;
|
|
109
|
+
if (input.ref !== undefined && input.ref !== null) {
|
|
110
|
+
if (typeof input.ref === 'number' && target === 'conversation')
|
|
111
|
+
ref = `tg:${input.ref}`;
|
|
112
|
+
else if (typeof input.ref === 'string')
|
|
113
|
+
ref = input.ref.toLowerCase();
|
|
114
|
+
else
|
|
115
|
+
return { ok: false, error: 'bad-target' };
|
|
116
|
+
}
|
|
117
|
+
let comment = null;
|
|
118
|
+
if (input.comment !== undefined && input.comment !== null) {
|
|
119
|
+
if (target !== 'doc' || typeof input.comment !== 'string' || !COMMENT_RE.test(input.comment))
|
|
120
|
+
return { ok: false, error: 'bad-target' };
|
|
121
|
+
comment = input.comment;
|
|
122
|
+
}
|
|
123
|
+
if (!ID_RE.test(canonicalId) || !validRef(target, ref))
|
|
124
|
+
return { ok: false, error: 'bad-target' };
|
|
125
|
+
const link = { id: canonicalId, target, ref, comment };
|
|
126
|
+
// Round-trip through the one parser, so the builder can never emit a link the app refuses.
|
|
127
|
+
const frag = canonicalFragment(link);
|
|
128
|
+
if (!parseAgentLink(frag))
|
|
129
|
+
return { ok: false, error: 'bad-target' };
|
|
130
|
+
return { ok: true, url: AGENT_LINK_WEB_BASE + frag, appUrl: AGENT_LINK_APP_BASE + frag, link };
|
|
131
|
+
}
|
|
132
|
+
function load(file, read) {
|
|
133
|
+
try {
|
|
134
|
+
const r = read(file, { repair: false });
|
|
135
|
+
if (!r)
|
|
136
|
+
return { kind: 'absent' };
|
|
137
|
+
if (r.encrypted || !r.privateKey)
|
|
138
|
+
return { kind: 'locked', publicKey: r.publicKey };
|
|
139
|
+
return { kind: 'ok', publicKey: r.publicKey, privateKey: r.privateKey };
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
// @silent-fallback-ok — IdentityFileInvalidError (or any read failure) is reported as identity-unreadable
|
|
143
|
+
return { kind: 'invalid' };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The identity a link names (spec §2a). Strict: when `<stateDir>/identity.json` exists it alone
|
|
148
|
+
* decides (unusable → identity-unreadable, encrypted → identity-key-locked, no fall-through); the
|
|
149
|
+
* Threadline legacy file is used only when it is absent; both readable with different keys →
|
|
150
|
+
* identity-split. The id is computed from the public key, never read from a stored field.
|
|
151
|
+
*/
|
|
152
|
+
export function readLinkIdentity(stateDir, deps = {}) {
|
|
153
|
+
const read = deps.read ?? readIdentityKeyFile;
|
|
154
|
+
const mainFile = path.join(stateDir, 'identity.json');
|
|
155
|
+
const legacyFile = path.join(stateDir, 'threadline', 'identity.json');
|
|
156
|
+
const main = load(mainFile, read);
|
|
157
|
+
const legacy = load(legacyFile, read);
|
|
158
|
+
if (main.kind === 'absent') {
|
|
159
|
+
if (legacy.kind === 'absent')
|
|
160
|
+
return { ok: false, error: 'no-agent-identity' };
|
|
161
|
+
if (legacy.kind === 'invalid')
|
|
162
|
+
return { ok: false, error: 'identity-unreadable' };
|
|
163
|
+
if (legacy.kind === 'locked')
|
|
164
|
+
return { ok: false, error: 'identity-key-locked' };
|
|
165
|
+
return { ok: true, canonicalId: computeCanonicalId(legacy.publicKey), publicKey: legacy.publicKey, privateKey: legacy.privateKey, file: legacyFile };
|
|
166
|
+
}
|
|
167
|
+
if (main.kind === 'invalid')
|
|
168
|
+
return { ok: false, error: 'identity-unreadable' };
|
|
169
|
+
if (main.kind === 'locked')
|
|
170
|
+
return { ok: false, error: 'identity-key-locked' };
|
|
171
|
+
if ((legacy.kind === 'ok' || legacy.kind === 'locked') && !legacy.publicKey.equals(main.publicKey)) {
|
|
172
|
+
return { ok: false, error: 'identity-split' };
|
|
173
|
+
}
|
|
174
|
+
return { ok: true, canonicalId: computeCanonicalId(main.publicKey), publicKey: main.publicKey, privateKey: main.privateKey, file: mainFile };
|
|
175
|
+
}
|
|
176
|
+
/** A nonce is exactly 32 bytes as unpadded base64url; any other spelling is refused. */
|
|
177
|
+
export function parseNonce(raw) {
|
|
178
|
+
if (typeof raw !== 'string' || !/^[A-Za-z0-9_-]{43}$/.test(raw))
|
|
179
|
+
return null;
|
|
180
|
+
const bytes = Buffer.from(raw, 'base64url');
|
|
181
|
+
if (bytes.length !== 32 || bytes.toString('base64url') !== raw)
|
|
182
|
+
return null;
|
|
183
|
+
return raw;
|
|
184
|
+
}
|
|
185
|
+
/** The exact bytes the identity key signs (spec §2a). The fixed first line is domain separation. */
|
|
186
|
+
export function proofTranscript(canonicalId, deviceId, host, nonce) {
|
|
187
|
+
return Buffer.from(`${PROOF_DOMAIN}\n${canonicalId}\n${deviceId}\n${host}\n${nonce}`, 'utf-8');
|
|
188
|
+
}
|
|
189
|
+
const PKCS8_ED25519_PREFIX = Buffer.from('302e020100300506032b657004220420', 'hex');
|
|
190
|
+
const SPKI_ED25519_PREFIX = Buffer.from('302a300506032b6570032100', 'hex');
|
|
191
|
+
/** Sign a proof transcript with the raw 32-byte Ed25519 private key. */
|
|
192
|
+
export function signProof(privateKey, transcript) {
|
|
193
|
+
const key = crypto.createPrivateKey({ key: Buffer.concat([PKCS8_ED25519_PREFIX, privateKey]), format: 'der', type: 'pkcs8' });
|
|
194
|
+
return crypto.sign(null, transcript, key);
|
|
195
|
+
}
|
|
196
|
+
/** Verify a proof (used by tests, and the same check the app makes). */
|
|
197
|
+
export function verifyProof(publicKey, transcript, signature) {
|
|
198
|
+
try {
|
|
199
|
+
const key = crypto.createPublicKey({ key: Buffer.concat([SPKI_ED25519_PREFIX, publicKey]), format: 'der', type: 'spki' });
|
|
200
|
+
return crypto.verify(null, transcript, key, signature);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return false; // @silent-fallback-ok — a malformed key is simply a failed verification
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=AgentLinks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentLinks.js","sourceRoot":"","sources":["../../src/core/AgentLinks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAA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KAAK,IAAI,KAAK,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;AACjG,CAAC;AAED,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;AACpF,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;AAE3E,wEAAwE;AACxE,MAAM,UAAU,SAAS,CAAC,UAAkB,EAAE,UAAkB;IAC9D,MAAM,GAAG,GAAG,MAAM,CAAC,gBAAgB,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC9H,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;AAC5C,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,UAAkB,EAAE,SAAiB;IAClF,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,CAAC,eAAe,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1H,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC,CAAC,wEAAwE;IACxF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SEC-127: ids that arrive from peers (message ids, thread ids) become file names.
|
|
3
|
+
* An id is only usable as a file name when it is ONE plain path component, so
|
|
4
|
+
* `../`, an absolute path or a NUL can never reach a file outside the folder the
|
|
5
|
+
* caller joins it into. Every legitimate id (UUIDs, `msg-…`, `thr-…`, `thread-…`,
|
|
6
|
+
* relay ids) passes.
|
|
7
|
+
*
|
|
8
|
+
* Length bound, in BYTES: file systems cap one file name at 255 bytes (APFS, ext4,
|
|
9
|
+
* NTFS). The longest name built from an id is ThreadLog's rotation temp file
|
|
10
|
+
* `<id>.log.jsonl.<pid>.rot.tmp`: `.log.jsonl.` (11) + a pid of at most 7 digits
|
|
11
|
+
* (Linux pid_max 4194304) + `.rot.tmp` (8) = 26 bytes of suffix, so the id may
|
|
12
|
+
* use 255 - 26 = 229. (MessageStore's `<id>.json.tmp.<pid>` and ThreadLog's
|
|
13
|
+
* `<id>.meta.json.<pid>.tmp` are shorter.) Wire ids are capped far lower
|
|
14
|
+
* (MESSAGE_ID_MAX = 128 in InboundIdLedger), so no real id is refused.
|
|
15
|
+
*/
|
|
16
|
+
export declare const MAX_FILE_ID_BYTES: number;
|
|
17
|
+
export declare function isSafeFileId(id: unknown): id is string;
|
|
18
|
+
//# sourceMappingURL=safeFileId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeFileId.d.ts","sourceRoot":"","sources":["../../src/core/safeFileId.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iBAAiB,QAAqD,CAAC;AAEpF,wBAAgB,YAAY,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,MAAM,CAOtD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SEC-127: ids that arrive from peers (message ids, thread ids) become file names.
|
|
3
|
+
* An id is only usable as a file name when it is ONE plain path component, so
|
|
4
|
+
* `../`, an absolute path or a NUL can never reach a file outside the folder the
|
|
5
|
+
* caller joins it into. Every legitimate id (UUIDs, `msg-…`, `thr-…`, `thread-…`,
|
|
6
|
+
* relay ids) passes.
|
|
7
|
+
*
|
|
8
|
+
* Length bound, in BYTES: file systems cap one file name at 255 bytes (APFS, ext4,
|
|
9
|
+
* NTFS). The longest name built from an id is ThreadLog's rotation temp file
|
|
10
|
+
* `<id>.log.jsonl.<pid>.rot.tmp`: `.log.jsonl.` (11) + a pid of at most 7 digits
|
|
11
|
+
* (Linux pid_max 4194304) + `.rot.tmp` (8) = 26 bytes of suffix, so the id may
|
|
12
|
+
* use 255 - 26 = 229. (MessageStore's `<id>.json.tmp.<pid>` and ThreadLog's
|
|
13
|
+
* `<id>.meta.json.<pid>.tmp` are shorter.) Wire ids are capped far lower
|
|
14
|
+
* (MESSAGE_ID_MAX = 128 in InboundIdLedger), so no real id is refused.
|
|
15
|
+
*/
|
|
16
|
+
export const MAX_FILE_ID_BYTES = 255 - '.log.jsonl.'.length - 7 - '.rot.tmp'.length;
|
|
17
|
+
export function isSafeFileId(id) {
|
|
18
|
+
return typeof id === 'string'
|
|
19
|
+
&& id.length > 0
|
|
20
|
+
&& Buffer.byteLength(id, 'utf8') <= MAX_FILE_ID_BYTES
|
|
21
|
+
&& id !== '.'
|
|
22
|
+
&& id !== '..'
|
|
23
|
+
&& !/[/\\\0]/.test(id);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=safeFileId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeFileId.js","sourceRoot":"","sources":["../../src/core/safeFileId.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,GAAG,aAAa,CAAC,MAAM,GAAG,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC;AAEpF,MAAM,UAAU,YAAY,CAAC,EAAW;IACtC,OAAO,OAAO,EAAE,KAAK,QAAQ;WACxB,EAAE,CAAC,MAAM,GAAG,CAAC;WACb,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,iBAAiB;WAClD,EAAE,KAAK,GAAG;WACV,EAAE,KAAK,IAAI;WACX,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -4162,6 +4162,14 @@ export interface InstarConfig {
|
|
|
4162
4162
|
* Maturation board (docs/specs/maturation-board.md): a read-only, advisory page of every
|
|
4163
4163
|
* maturing feature. `enabled` is omitted by default so the developmentAgent gate decides.
|
|
4164
4164
|
*/
|
|
4165
|
+
/**
|
|
4166
|
+
* Permanent agent links (docs/specs/permanent-agent-links.md): links on instar.sh that name this
|
|
4167
|
+
* agent by its identity and open a page in the Instar app. Optional; absent or false = off. Read
|
|
4168
|
+
* live, so turning it on needs no restart.
|
|
4169
|
+
*/
|
|
4170
|
+
agentLinks?: {
|
|
4171
|
+
enabled?: boolean;
|
|
4172
|
+
};
|
|
4165
4173
|
/**
|
|
4166
4174
|
* Mobile pairing links (docs/specs/mobile-pairing-link.md): one-time links that add this
|
|
4167
4175
|
* agent to the Instar iPhone app. `enabled` is omitted by default so the developmentAgent
|