paseo-plugin-secure-input 0.0.0-stage → 0.2.1

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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/OVERVIEW.md +28 -0
  3. package/README.md +105 -2
  4. package/SECURITY.md +84 -0
  5. package/assets/icon.png +0 -0
  6. package/client/card.tsx +74 -0
  7. package/client/codes.ts +32 -0
  8. package/client/diagnostics-rows.ts +139 -0
  9. package/client/dialog-state.ts +59 -0
  10. package/client/dialog.tsx +292 -0
  11. package/client/envelope-cache.ts +85 -0
  12. package/client/fields.tsx +255 -0
  13. package/client/file-entry.ts +142 -0
  14. package/client/form-state.ts +198 -0
  15. package/client/globals.d.ts +19 -0
  16. package/client/outcome.ts +96 -0
  17. package/client/presentation.ts +114 -0
  18. package/client/sealing.ts +27 -0
  19. package/client/self-test.ts +96 -0
  20. package/client/settings.tsx +160 -0
  21. package/client/submit.ts +92 -0
  22. package/client/text.ts +47 -0
  23. package/client/tone.ts +36 -0
  24. package/client/web.ts +184 -0
  25. package/index.client.tsx +29 -0
  26. package/index.server.ts +6 -0
  27. package/npm-shrinkwrap.json +60 -0
  28. package/package.json +68 -4
  29. package/paseo-plugin.json +6 -0
  30. package/server/core/continuation.ts +151 -0
  31. package/server/core/entries.ts +89 -0
  32. package/server/core/outbox.ts +555 -0
  33. package/server/core/registry-store.ts +185 -0
  34. package/server/core/registry.ts +1031 -0
  35. package/server/core/selftest.ts +60 -0
  36. package/server/core/view.ts +38 -0
  37. package/server/io/atomic.ts +119 -0
  38. package/server/io/deadline.ts +28 -0
  39. package/server/io/descriptor.ts +36 -0
  40. package/server/io/directory.ts +40 -0
  41. package/server/io/drop.ts +434 -0
  42. package/server/io/legacy-shim.ts +108 -0
  43. package/server/io/ownership.ts +8 -0
  44. package/server/io/private-file.ts +86 -0
  45. package/server/paseo/bounded.ts +13 -0
  46. package/server/paseo/handlers.ts +124 -0
  47. package/server/paseo/hooks.ts +106 -0
  48. package/server/paseo/plugin.ts +341 -0
  49. package/server/paseo/runtime.ts +409 -0
  50. package/server/paseo/tools.ts +178 -0
  51. package/shared/bytes.ts +100 -0
  52. package/shared/canonical.ts +32 -0
  53. package/shared/card.ts +41 -0
  54. package/shared/contracts.ts +128 -0
  55. package/shared/errors.ts +48 -0
  56. package/shared/limits.ts +118 -0
  57. package/shared/request-id.ts +9 -0
  58. package/shared/request.ts +66 -0
  59. package/shared/sanitize.ts +101 -0
  60. package/shared/seal.ts +292 -0
  61. package/shared/shown.ts +12 -0
  62. package/shared/text.ts +39 -0
  63. package/shared/view.ts +42 -0
  64. package/skills/secure-input/SKILL.md +150 -0
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "paseo-plugin-secure-input",
3
+ "version": "0.2.1",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "paseo-plugin-secure-input",
9
+ "version": "0.2.1",
10
+ "license": "MIT",
11
+ "dependencies": {
12
+ "@noble/ciphers": "2.4.0",
13
+ "@noble/curves": "2.4.0",
14
+ "@noble/hashes": "2.4.0"
15
+ },
16
+ "engines": {
17
+ "node": ">=22.12.0"
18
+ }
19
+ },
20
+ "node_modules/@noble/ciphers": {
21
+ "version": "2.4.0",
22
+ "resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-2.4.0.tgz",
23
+ "integrity": "sha512-AnjFn0Jv92laAkvMrghlFZq4qQCIN/4DxFV/eooqtC2YTjB7kBeLMS2T9KJX4Dn+ZVXLOwK0lSgqDtx9gvxtiw==",
24
+ "license": "MIT",
25
+ "engines": {
26
+ "node": ">= 20.19.0"
27
+ },
28
+ "funding": {
29
+ "url": "https://paulmillr.com/funding/"
30
+ }
31
+ },
32
+ "node_modules/@noble/curves": {
33
+ "version": "2.4.0",
34
+ "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-2.4.0.tgz",
35
+ "integrity": "sha512-P4/62zrgfH33CneE3Dn4WhJVA22YUU0eR51wKIan4NVRvwsA0YnPTwWGpNbpuacSujmSFLvyzpyuR30+fbq2Ew==",
36
+ "license": "MIT",
37
+ "dependencies": {
38
+ "@noble/hashes": "2.4.0"
39
+ },
40
+ "engines": {
41
+ "node": ">= 20.19.0"
42
+ },
43
+ "funding": {
44
+ "url": "https://paulmillr.com/funding/"
45
+ }
46
+ },
47
+ "node_modules/@noble/hashes": {
48
+ "version": "2.4.0",
49
+ "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.4.0.tgz",
50
+ "integrity": "sha512-X5XaVWZIBCT7HHZGm5I7ZQXDwLG+bGXuSrMQAW+7Zvl87h1kmc1ZB1VSRJcpUfoUrGQp4Fkoxm5kZ+Ms+aW+eA==",
51
+ "license": "MIT",
52
+ "engines": {
53
+ "node": ">= 20.19.0"
54
+ },
55
+ "funding": {
56
+ "url": "https://paulmillr.com/funding/"
57
+ }
58
+ }
59
+ }
60
+ }
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "paseo-plugin-secure-input",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.1",
4
+ "description": "Secure secret input for Paseo agents: a typed value or a whole file travels sealed to the daemon and lands in a short-lived file; the agent gets its path, never the value",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "dutchakdev",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/dutchakdev/paseo-plugin-secure-input.git"
11
+ },
12
+ "homepage": "https://github.com/dutchakdev/paseo-plugin-secure-input#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/dutchakdev/paseo-plugin-secure-input/issues"
15
+ },
16
+ "engines": {
17
+ "node": ">=22.12.0"
18
+ },
19
+ "os": [
20
+ "darwin",
21
+ "linux"
22
+ ],
23
+ "keywords": [
24
+ "paseo",
25
+ "paseo-plugin",
26
+ "secrets",
27
+ "security"
28
+ ],
29
+ "scripts": {
30
+ "typecheck": "tsc -p tsconfig.server.json && tsc -p tsconfig.client.json && tsc -p tsconfig.client-tests.json",
31
+ "test": "vitest run",
32
+ "check": "npm run typecheck && npm test",
33
+ "prepack": "node scripts/shrinkwrap.mjs write",
34
+ "postpack": "node scripts/shrinkwrap.mjs remove"
35
+ },
36
+ "dependencies": {
37
+ "@noble/ciphers": "2.4.0",
38
+ "@noble/curves": "2.4.0",
39
+ "@noble/hashes": "2.4.0"
40
+ },
41
+ "devDependencies": {
42
+ "@getpaseo/client": "0.14.0-beta.1",
43
+ "@getpaseo/plugin": "0.14.0-beta.1",
44
+ "@getpaseo/protocol": "0.14.0-beta.1",
45
+ "@getpaseo/relay": "0.14.0-beta.1",
46
+ "@modelcontextprotocol/sdk": "1.32.1",
47
+ "@tanstack/react-query": "^5.90.11",
48
+ "@types/node": "^22.0.0",
49
+ "@types/react": "~19.2.0",
50
+ "react": "19.1.0",
51
+ "react-native": "0.81.5",
52
+ "semver": "7.8.5",
53
+ "typescript": "^5.9.3",
54
+ "vitest": "^4.1.11",
55
+ "zod": "^4.4.3"
56
+ },
57
+ "files": [
58
+ "paseo-plugin.json",
59
+ "npm-shrinkwrap.json",
60
+ "OVERVIEW.md",
61
+ "index.client.tsx",
62
+ "index.server.ts",
63
+ "client/",
64
+ "server/",
65
+ "shared/",
66
+ "skills/",
67
+ "assets/icon.png",
68
+ "SECURITY.md"
69
+ ]
70
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "id": "secure-input",
3
+ "description": "Agents ask for secrets through a form; each value or file lands in a short-lived file the agent moves without reading it",
4
+ "icon": "assets/icon.png",
5
+ "requirements": { "paseo": ">=0.14.0-beta.1" }
6
+ }
@@ -0,0 +1,151 @@
1
+ import type { ErrorCode } from "../../shared/errors";
2
+ import { DROP_TTL_MS, MAX_RETRIES } from "../../shared/limits";
3
+ import { filePath, setPath } from "../io/drop";
4
+ import type { RequestRecord } from "./registry";
5
+ import type { ReleasedBy } from "./registry-store";
6
+
7
+ const PREFIX = "[secure-input]";
8
+
9
+ const COUNT_WORDS: readonly string[] = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"];
10
+
11
+ /**
12
+ * "Three submissions failed": how many submissions it takes to reach the retry limit, in words, as the start of a
13
+ * sentence. Built from the number the registry counts to, so the sentence cannot say another one. A number past the
14
+ * list is written in digits.
15
+ */
16
+ export function submissionsFailed(count: number): string {
17
+ return `${COUNT_WORDS[count] ?? String(count)} ${count === 1 ? "submission" : "submissions"} failed`;
18
+ }
19
+
20
+ /** One sentence for every code a request can be rejected with, so a new code is a compile error until it has one. */
21
+ const HINTS: Record<ErrorCode, string> = {
22
+ invalid_request: "The request or the submitted values could not be read.",
23
+ request_already_pending: "Another request from you was still open.",
24
+ unknown_agent: "The plugin could not tell which agent asked.",
25
+ service_unavailable: "The plugin was not able to take the request.",
26
+ write_failed: "The plugin could not write the files.",
27
+ retry_limit: `${submissionsFailed(MAX_RETRIES)}: the sealed values could not be opened.`,
28
+ request_closed: "The request was no longer open when the user answered, for example because the plugin restarted.",
29
+ decrypt_failed: "The sealed values could not be opened.",
30
+ };
31
+
32
+ const NO_REASON = "The plugin did not record a reason.";
33
+
34
+ /**
35
+ * Rejections the agent cannot repair by itself: a new request would only fail the same way, and every request makes the
36
+ * user type the values again. Their message ends by sending the agent to the user instead of to a new request.
37
+ */
38
+ const ONLY_THE_USER_CAN_FIX: ReadonlySet<ErrorCode> = new Set([
39
+ "invalid_request",
40
+ "unknown_agent",
41
+ "service_unavailable",
42
+ "write_failed",
43
+ "retry_limit",
44
+ "decrypt_failed",
45
+ ]);
46
+
47
+ const FIX_AND_ASK = "Fix the cause and make a new request.";
48
+ const TELL_THE_USER = "Tell the user what happened. Do not make a new request yourself; each one makes the user type the values again.";
49
+
50
+ /** What a rejection says: the code (when this version knows it), its sentence and what to do next. */
51
+ function reasonOf(code: ErrorCode | null): { named: string; hint: string; next: string } {
52
+ // `Object.hasOwn`, because a code the table does not know must not reach `constructor` or `__proto__`.
53
+ if (code === null || typeof code !== "string" || !Object.hasOwn(HINTS, code)) return { named: "", hint: NO_REASON, next: TELL_THE_USER };
54
+ return { named: ` (${code})`, hint: HINTS[code], next: ONLY_THE_USER_CAN_FIX.has(code) ? TELL_THE_USER : FIX_AND_ASK };
55
+ }
56
+
57
+ /**
58
+ * When the files of a set went, for each way of release that has a message: the agent is told this when the message
59
+ * about the files was still waiting when they went. A set the agent released, or that went at the end of the turn the
60
+ * message started, has none: the agent took them, or was told and had its turn.
61
+ */
62
+ const GONE: Readonly<Partial<Record<ReleasedBy, string>>> = {
63
+ time: `${DROP_TTL_MS / 60_000} minutes after they were written`,
64
+ restart: "when the plugin restarted",
65
+ stop: "when the plugin stopped",
66
+ human: "by the user",
67
+ };
68
+
69
+ /**
70
+ * A path as a shell reads it: as it is when it is made of letters, digits and `_./-` alone, and otherwise in single
71
+ * quotes, a quote in it written as `'\''`. Nothing in a path quoted so is expanded or run.
72
+ */
73
+ export function shellPath(path: string): string {
74
+ return /^[A-Za-z0-9_./-]+$/.test(path) ? path : `'${path.replaceAll("'", "'\\''")}'`;
75
+ }
76
+
77
+ /** What the agent is told of a delivery: where each value is, what never to do with it, what to do, and when the files go. */
78
+ function deliveredText(head: string, record: RequestRecord, drop: string): string | null {
79
+ const { written, deleteBy } = record;
80
+ if (written === null || deleteBy === null) return null;
81
+ const empty = record.request.fields.map((field) => field.key).filter((key) => !written.includes(key));
82
+ return [
83
+ `${head} delivered ${written.length} value(s) as files only your OS user can read:`,
84
+ ...written.map((key) => ` ${key} → ${shellPath(filePath(drop, record.id, key))}`),
85
+ ...(empty.length > 0 ? [`Left empty by the user, so no file: ${empty.join(", ")}.`] : []),
86
+ "The values were not shown to you. Never let the content of a file or directory whose name starts with si-secret- reach you: do not read, print, open, compare or log it, and do not pass it as an argument.",
87
+ "Move each value where it is needed only by redirection or by copy, for example `command < PATH` or `cp PATH DESTINATION`.",
88
+ `Then delete the directory (\`rm -r ${shellPath(setPath(drop, record.id))}\`) or call release_secret.`,
89
+ `The files are deleted at the end of the turn this message starts, and at ${new Date(deleteBy).toISOString()} at the latest.`,
90
+ ].join("\n");
91
+ }
92
+
93
+ /** What the agent is told of a set that went before its message reached it, or null when there is nothing to tell. */
94
+ function releasedText(head: string, by: ReleasedBy | undefined): string | null {
95
+ // `Object.hasOwn`, because a way this version does not know must not reach `constructor` or `__proto__`.
96
+ if (by === undefined || typeof by !== "string" || !Object.hasOwn(GONE, by)) return null;
97
+ return `${head} was delivered, but its files were deleted ${GONE[by] as string}, before this message reached you. Nothing is left to move. If the values are still needed, make a new request.`;
98
+ }
99
+
100
+ /**
101
+ * The fixed text an agent receives about a request, or null when the record has nothing to tell. Built from the
102
+ * record's id, the keys it asked for and the keys that were written, its deadline, its error code and how it ended, and
103
+ * from the drop the files are in; nothing the agent wrote in the request (reason, labels) is repeated. The record holds
104
+ * no value, so no text can.
105
+ */
106
+ export function continuationText(record: RequestRecord, drop: string): string | null {
107
+ const head = `${PREFIX} Request ${record.id}`;
108
+ switch (record.state) {
109
+ case "delivered":
110
+ return deliveredText(head, record, drop);
111
+ case "released":
112
+ return releasedText(head, record.releasedBy);
113
+ case "rejected": {
114
+ const { named, hint, next } = reasonOf(record.errorCode);
115
+ return `${head} was rejected before any file was written${named}. ${hint} ${next}`;
116
+ }
117
+ case "declined":
118
+ return `${head}: the user declined to provide the values. Do not ask again in a different way. Ask the user how they want to proceed.`;
119
+ case "expired":
120
+ if (record.expiredBy === "restart") return `${head} expired when the plugin restarted. Nothing was delivered. If the values are still needed, make a new request.`;
121
+ return `${head} expired before the user answered. If the values are still needed, make a new request.`;
122
+ default:
123
+ return null;
124
+ }
125
+ }
126
+
127
+ /** The states whose arrival the agent is told of. `released` is not one: a message that still waits says it instead (`continuationText`). */
128
+ const ANNOUNCED: ReadonlySet<RequestRecord["state"]> = new Set(["delivered", "rejected", "declined", "expired"]);
129
+
130
+ /** Whether a request that has just come to its state is told to its agent. */
131
+ export function announces(record: RequestRecord): boolean {
132
+ return ANNOUNCED.has(record.state);
133
+ }
134
+
135
+ /** Sent when a second, different submission reached a request whose values were delivered. Built from the id alone. */
136
+ export function tamperText(record: RequestRecord): string {
137
+ return (
138
+ `${PREFIX} Warning for request ${record.id}: a second, different submission arrived after the values were delivered. ` +
139
+ "The files you were given may have held values the user did not type. Tell the user to check what you did with them and to rotate the secret."
140
+ );
141
+ }
142
+
143
+ /**
144
+ * The message an outbox item stands for, or null when the record has nothing to say for it: the tamper warning only
145
+ * when the registry flagged the request as tampered with, the continuation only when the record has one at the moment
146
+ * it is sent. `drop` is where the files of a set are.
147
+ */
148
+ export function messageFor(record: RequestRecord, kind: "continuation" | "tamper", drop: string): string | null {
149
+ if (kind === "tamper") return record.tamper ? tamperText(record) : null;
150
+ return continuationText(record, drop);
151
+ }
@@ -0,0 +1,89 @@
1
+ import { decodedLength, fromBase64Url, utf8, utf8Length } from "../../shared/bytes";
2
+ import { SecureInputError } from "../../shared/errors";
3
+ import { KEY_PATTERN, caseCollision, isValidKey } from "../../shared/limits";
4
+ import { LIMITS, type Field, type InputRequest } from "../../shared/request";
5
+ import type { FileEntry, PayloadEntry } from "../../shared/seal";
6
+ import { hasLoneSurrogate } from "../../shared/text";
7
+ import type { DropFile } from "../io/drop";
8
+
9
+ function invalid(detail: string): never {
10
+ throw new SecureInputError("invalid_request", detail);
11
+ }
12
+
13
+ function isFileEntry(entry: PayloadEntry): entry is FileEntry {
14
+ return Object.hasOwn(entry, "file");
15
+ }
16
+
17
+ /**
18
+ * Checks what the app sent against what the agent asked for, and turns it into the files of the set: a text as its
19
+ * UTF-8, a file as its bytes. Errors name keys only: a value must never reach an error message.
20
+ *
21
+ * Every key is a valid one, said once, and no two name one file when case is ignored: the declared keys first, then the
22
+ * human's own, which are always taken. A declared field gets the kind it was declared with (a text when it names
23
+ * none). A text is at most `LIMITS.valueBytes` and holds no surrogate without its partner; a file is base64url and at
24
+ * most `LIMITS.fileBytes`. An empty text or an empty file is left empty: a declared optional field is then skipped, a
25
+ * required one refused, and a key of the human's gets no file. A submission that would write nothing is refused.
26
+ *
27
+ * The bytes that come out are the caller's to wipe. On a refusal every byte array made so far is wiped here.
28
+ */
29
+ export function validateEntries(request: InputRequest, entries: readonly PayloadEntry[]): { written: DropFile[]; skipped: string[] } {
30
+ const written: DropFile[] = [];
31
+ try {
32
+ if (entries.length > LIMITS.fields) invalid("too many entries");
33
+
34
+ const seen = new Set<string>();
35
+ for (const entry of entries) {
36
+ if (!isValidKey(entry.key)) invalid(KEY_PATTERN.test(entry.key) ? "a key name is reserved" : "a key is not a valid identifier");
37
+ if (seen.has(entry.key)) invalid(`${entry.key} appears more than once`);
38
+ seen.add(entry.key);
39
+ }
40
+
41
+ const declared = new Map<string, Field>(request.fields.map((field) => [field.key, field] as const));
42
+ const theirs = entries.filter((entry) => !declared.has(entry.key)).map((entry) => entry.key);
43
+ const collision = caseCollision([...declared.keys(), ...theirs]);
44
+ if (collision !== null) invalid(`${collision[0]} and ${collision[1]} differ only in letter case`);
45
+
46
+ const filled = new Set<string>();
47
+ for (const entry of entries) {
48
+ const field = declared.get(entry.key);
49
+ if (field !== undefined && (field.kind === "file") !== isFileEntry(entry)) invalid(field.kind === "file" ? `${entry.key} must be a file` : `${entry.key} must be text`);
50
+ const bytes = isFileEntry(entry) ? fileBytes(entry) : textBytes(entry.key, entry.value);
51
+ if (bytes.length === 0) continue;
52
+ written.push({ key: entry.key, bytes });
53
+ filled.add(entry.key);
54
+ }
55
+
56
+ const skipped: string[] = [];
57
+ for (const field of request.fields) {
58
+ if (filled.has(field.key)) continue;
59
+ if (field.optional !== true) invalid(`${field.key} is required`);
60
+ skipped.push(field.key);
61
+ }
62
+ if (written.length === 0) invalid("nothing to write");
63
+ return { written, skipped };
64
+ } catch (error) {
65
+ for (const file of written) file.bytes.fill(0);
66
+ throw error;
67
+ }
68
+ }
69
+
70
+ /** A text as the bytes of its file: its UTF-8, measured before it is made. */
71
+ function textBytes(key: string, value: string): Uint8Array {
72
+ if (utf8Length(value) > LIMITS.valueBytes) invalid(`${key} is larger than the limit`);
73
+ if (hasLoneSurrogate(value)) invalid(`${key} contains invalid Unicode`);
74
+ return utf8.encode(value);
75
+ }
76
+
77
+ /**
78
+ * A file as the bytes it was. One over the limit is refused from the length of its text, before it is decoded, so no
79
+ * array of it is ever made (`decodedLength` is the length of what the decoder would give). A text the decoder refuses
80
+ * leaves no array of it either (`fromBase64Url`), and what the decoder said is not passed on.
81
+ */
82
+ function fileBytes(entry: FileEntry): Uint8Array {
83
+ if (decodedLength(entry.file) > LIMITS.fileBytes) invalid(`${entry.key} is larger than the limit`);
84
+ try {
85
+ return fromBase64Url(entry.file);
86
+ } catch {
87
+ invalid(`${entry.key} is not a file the plugin can read`);
88
+ }
89
+ }