podster 0.0.1-test.3 → 0.0.1-test.5
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/build/core/repository.js +33 -9
- package/build/core/results.js +4 -1
- package/build/core/runtime.js +10 -1
- package/build/node/claude-engine.js +27 -1
- package/build/node/github-api.js +2 -3
- package/build/node/repo-path.js +1 -1
- package/git/credential-helper +7 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/build/core/repository.js
CHANGED
|
@@ -24,13 +24,18 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import { isFullName } from "./policy.js";
|
|
26
26
|
export { isFullName };
|
|
27
|
-
|
|
27
|
+
const KEY_NAME = /^[a-z_]{1,40}$/;
|
|
28
|
+
/** The JSON type name of a value, as a fixed word. */
|
|
29
|
+
const typeName = (v) => (v === null ? "null" : Array.isArray(v) ? "array" : typeof v);
|
|
28
30
|
export class RepoPathError extends Error {
|
|
29
31
|
code;
|
|
30
32
|
/** Worth trying again later: the network, a rate limit, a branch that moved while read. */
|
|
31
33
|
transient;
|
|
32
|
-
|
|
34
|
+
/** Fixed-shape facts about a refused answer, for the log: key names, a length, a type. Never a value. */
|
|
35
|
+
detail;
|
|
36
|
+
constructor(code, transient = false, detail = {}) {
|
|
33
37
|
super(`repository path: ${code}`);
|
|
38
|
+
this.detail = detail;
|
|
34
39
|
this.code = /^[a-z][a-z0-9_]{0,63}$/.test(code) ? code : "unknown";
|
|
35
40
|
this.transient = transient;
|
|
36
41
|
}
|
|
@@ -52,7 +57,21 @@ export const RENEW_BEFORE_MS = 4 * 60 * 1000;
|
|
|
52
57
|
export const BRANCH_PREFIX = "podster/";
|
|
53
58
|
/** The fixed identity of a commit Runner makes, so no name or address from anywhere else is ever used. */
|
|
54
59
|
export const COMMIT_IDENTITY = { name: "Podster Runner", email: "runner@podster.invalid" };
|
|
55
|
-
|
|
60
|
+
/**
|
|
61
|
+
* The longest installation token Runner takes. GitHub's installation tokens are now `ghs_APPID_JWT`, "~520 characters"
|
|
62
|
+
* that "will vary", with no published maximum, and GitHub says to treat them as opaque (changelog, 2026-04-24 and
|
|
63
|
+
* 2026-10-02). This leaves room for that to grow while keeping a hostile answer bounded. The server holds the same bound
|
|
64
|
+
* (`INSTALLATION_TOKEN_MAX` in `crates/core/src/repo_access.rs`).
|
|
65
|
+
*/
|
|
66
|
+
export const MAX_ACCESS_TOKEN = 4096;
|
|
67
|
+
/**
|
|
68
|
+
* A token's characters: a JWT's base64url segments, their dots, and the `_` of `ghs_APPID_`. Never whitespace, a control
|
|
69
|
+
* character, `:`, `@`, `/`, `=` or anything else that could end or bend an `Authorization` header, a URL or a line of Git's
|
|
70
|
+
* credential protocol.
|
|
71
|
+
*/
|
|
72
|
+
const TOKEN = new RegExp(`^[A-Za-z0-9._-]{20,${MAX_ACCESS_TOKEN}}$`);
|
|
73
|
+
/** Whether a string can be an installation token: its characters and length, nothing about its contents. */
|
|
74
|
+
export const isAccessToken = (v) => TOKEN.test(v);
|
|
56
75
|
const COMMIT = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
|
|
57
76
|
const TASK = /^[a-z0-9_-]{1,128}$/;
|
|
58
77
|
/** A branch name Runner will use or accept as a default branch: plain segments, no ref syntax. */
|
|
@@ -85,17 +104,22 @@ export const pullRequestUrl = (full_name, number) => `https://${GIT_HOST}/${full
|
|
|
85
104
|
*/
|
|
86
105
|
export function readAccess(answer, scope, now) {
|
|
87
106
|
if (!isObj(answer))
|
|
88
|
-
throw new RepoPathError("
|
|
107
|
+
throw new RepoPathError("access_not_object", false, { type: typeName(answer) });
|
|
89
108
|
const keys = ["token", "expires_at", "repository", "clone_url", "permissions", "authority_ends_at"];
|
|
90
|
-
if (Object.keys(answer).length !== keys.length || !keys.every((k) => Object.hasOwn(answer, k)))
|
|
91
|
-
|
|
109
|
+
if (Object.keys(answer).length !== keys.length || !keys.every((k) => Object.hasOwn(answer, k))) {
|
|
110
|
+
// Only key names that look like names, at most 10, so a hostile answer can't put text in a log.
|
|
111
|
+
const names = Object.keys(answer).sort().slice(0, 10).map((k) => (KEY_NAME.test(k) ? k : "?")).join(",");
|
|
112
|
+
throw new RepoPathError("access_fields", false, { count: Object.keys(answer).length, ...(names ? { names } : {}) });
|
|
113
|
+
}
|
|
92
114
|
const { token, expires_at, repository, clone_url, permissions, authority_ends_at } = answer;
|
|
93
|
-
if (typeof token !== "string"
|
|
94
|
-
throw new RepoPathError("
|
|
115
|
+
if (typeof token !== "string")
|
|
116
|
+
throw new RepoPathError("access_token_format", false, { type: typeName(token) });
|
|
117
|
+
if (!isAccessToken(token))
|
|
118
|
+
throw new RepoPathError("access_token_format", false, { length: token.length, prefix: /^[a-z]{3}_/.test(token) ? "yes" : "no" });
|
|
95
119
|
if (!isCount(expires_at) || expires_at <= now)
|
|
96
120
|
throw new RepoPathError("access_expired");
|
|
97
121
|
if (!(authority_ends_at === null || isCount(authority_ends_at)))
|
|
98
|
-
throw new RepoPathError("
|
|
122
|
+
throw new RepoPathError("access_authority_invalid");
|
|
99
123
|
if (!isObj(permissions) || Object.keys(permissions).length !== 3 || permissions.contents !== "write" || permissions.pull_requests !== "write" || permissions.metadata !== "read")
|
|
100
124
|
throw new RepoPathError("access_permissions");
|
|
101
125
|
if (!isFullName(repository) || !sameName(repository, scope.full_name))
|
package/build/core/results.js
CHANGED
|
@@ -29,8 +29,11 @@ const REDACTED = "[redacted]";
|
|
|
29
29
|
*/
|
|
30
30
|
const SECRETS = [
|
|
31
31
|
{ pattern: /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY-----|$)/g },
|
|
32
|
+
// GitHub's tokens, old (`ghs_` and 36 characters) and new (`ghs_APPID_JWT`, about 520): `_`, `-` and a dot that joins
|
|
33
|
+
// two segments are all part of one, so the whole token goes, not just up to its first `_` or `.`. It runs before
|
|
34
|
+
// `sk-ant-` and the rest, so another rule can't take a piece from the middle of one and leave its ends.
|
|
35
|
+
{ pattern: /gh[pousr]_(?:[A-Za-z0-9_-]|\.(?=[A-Za-z0-9_-])){20,}/g },
|
|
32
36
|
{ pattern: /sk-ant-[A-Za-z0-9_-]{8,}/g },
|
|
33
|
-
{ pattern: /gh[pousr]_[A-Za-z0-9]{20,}/g },
|
|
34
37
|
{ pattern: /github_pat_[A-Za-z0-9_]{20,}/g },
|
|
35
38
|
{ pattern: /(?<![A-Za-z0-9])sk-[A-Za-z0-9_-]{20,}/g },
|
|
36
39
|
{ pattern: /(?<![A-Za-z0-9])(?:AKIA|ASIA)[0-9A-Z]{16}(?![A-Za-z0-9])/g },
|
package/build/core/runtime.js
CHANGED
|
@@ -18,7 +18,10 @@ export const systemClock = {
|
|
|
18
18
|
const NAME = /^[a-z][a-z0-9_.]{0,63}$/;
|
|
19
19
|
const ID_VALUE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
20
20
|
const CODE_VALUE = /^[a-z][a-z0-9_]{0,63}$/;
|
|
21
|
-
const
|
|
21
|
+
const NAMES_VALUE = /^[a-z_?]{1,40}(,[a-z_?]{1,40}){0,9}$/;
|
|
22
|
+
const PREFIX_VALUE = /^(yes|no)$/;
|
|
23
|
+
const TYPE_VALUE = /^(null|array|object|string|number|boolean|undefined|bigint|symbol|function)$/;
|
|
24
|
+
const NUMBER_FIELDS = new Set(["seq", "count", "status", "length"]);
|
|
22
25
|
const ID_FIELDS = new Set(["agent", "plugin_agent", "workspace", "task", "attempt_id"]);
|
|
23
26
|
/** The line a logger writes, with everything that isn't allowed dropped. */
|
|
24
27
|
export function logLine(at, outcome, fields = {}) {
|
|
@@ -28,6 +31,12 @@ export function logLine(at, outcome, fields = {}) {
|
|
|
28
31
|
line[name] = value;
|
|
29
32
|
else if (ID_FIELDS.has(name) && typeof value === "string" && ID_VALUE.test(value))
|
|
30
33
|
line[name] = value;
|
|
34
|
+
else if (name === "names" && typeof value === "string" && NAMES_VALUE.test(value))
|
|
35
|
+
line[name] = value;
|
|
36
|
+
else if (name === "prefix" && typeof value === "string" && PREFIX_VALUE.test(value))
|
|
37
|
+
line[name] = value;
|
|
38
|
+
else if (name === "type" && typeof value === "string" && TYPE_VALUE.test(value))
|
|
39
|
+
line[name] = value;
|
|
31
40
|
else if (name === "code" && typeof value === "string" && CODE_VALUE.test(value))
|
|
32
41
|
line[name] = value;
|
|
33
42
|
}
|
|
@@ -106,6 +106,32 @@ export const INSPECT_FAILED = {
|
|
|
106
106
|
};
|
|
107
107
|
/** Docker's own answer for an image it doesn't have, from `docker image inspect`. */
|
|
108
108
|
const NO_SUCH_IMAGE = /^(Error: |Error response from daemon: )?No such image: /m;
|
|
109
|
+
const JSON_NO_SUCH_IMAGE_PREFIX = "Error response from daemon: ";
|
|
110
|
+
/**
|
|
111
|
+
* Docker 28.5.1 answers a missing image as `Error response from daemon: {"message":"No such image: <id>"}`. Accepted
|
|
112
|
+
* only as one JSON object whose single key is `message` and whose value is "No such image: " plus the pinned ID or its
|
|
113
|
+
* short form; anything else is not Docker's answer for this image.
|
|
114
|
+
*/
|
|
115
|
+
function isJsonNoSuchImage(stderr, pinnedId) {
|
|
116
|
+
const text = stderr.trim();
|
|
117
|
+
if (!text.startsWith(JSON_NO_SUCH_IMAGE_PREFIX))
|
|
118
|
+
return false;
|
|
119
|
+
let parsed;
|
|
120
|
+
try {
|
|
121
|
+
parsed = JSON.parse(text.slice(JSON_NO_SUCH_IMAGE_PREFIX.length));
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
|
|
127
|
+
return false;
|
|
128
|
+
const keys = Object.keys(parsed);
|
|
129
|
+
if (keys.length !== 1 || keys[0] !== "message")
|
|
130
|
+
return false;
|
|
131
|
+
const message = parsed.message;
|
|
132
|
+
const hex = pinnedId.replace(/^sha256:/, "");
|
|
133
|
+
return typeof message === "string" && [pinnedId, hex, hex.slice(0, 12)].some((id) => message === `No such image: ${id}`);
|
|
134
|
+
}
|
|
109
135
|
/** A build's bound: Claude Code's image fetches its packages, so it can take minutes. */
|
|
110
136
|
const BUILD_TIMEOUT_MS = 30 * 60_000;
|
|
111
137
|
/**
|
|
@@ -124,7 +150,7 @@ export async function ensureImage(name, opts) {
|
|
|
124
150
|
if (present.code === 0)
|
|
125
151
|
return pinnedId;
|
|
126
152
|
// Rebuilt only when Docker says it hasn't the image (security review L4 on #470). Any other failure stops.
|
|
127
|
-
if (present.code !== 1 || present.cut || !NO_SUCH_IMAGE.test(present.stderr))
|
|
153
|
+
if (present.code !== 1 || present.cut || !(NO_SUCH_IMAGE.test(present.stderr) || isJsonNoSuchImage(present.stderr, pinnedId)))
|
|
128
154
|
throw new Error(INSPECT_FAILED[name]);
|
|
129
155
|
}
|
|
130
156
|
opts.notify(BUILDING[name]);
|
package/build/node/github-api.js
CHANGED
|
@@ -7,11 +7,10 @@
|
|
|
7
7
|
* The token is never logged, returned or put in an error; nor is anything GitHub answers, beyond the checked fields the
|
|
8
8
|
* caller reads.
|
|
9
9
|
*/
|
|
10
|
-
import { API_ORIGIN, RepoPathError } from "../core/repository.js";
|
|
10
|
+
import { API_ORIGIN, RepoPathError, isAccessToken } from "../core/repository.js";
|
|
11
11
|
import { transportEnvRefusal } from "./provider-transport.js";
|
|
12
12
|
export const MAX_GITHUB_ANSWER = 1024 * 1024;
|
|
13
13
|
export const GITHUB_TIMEOUT_MS = 30_000;
|
|
14
|
-
const TOKEN = /^[A-Za-z0-9_]{20,255}$/;
|
|
15
14
|
async function bounded(response) {
|
|
16
15
|
const reader = response.body?.getReader();
|
|
17
16
|
if (!reader)
|
|
@@ -37,7 +36,7 @@ export function githubApi(fetchImpl = fetch, env = process.env, execArgv = proce
|
|
|
37
36
|
if (refusal)
|
|
38
37
|
throw new Error(`Runner won't reach GitHub with this environment (${refusal}).`);
|
|
39
38
|
return async (request, token, signal) => {
|
|
40
|
-
if (!
|
|
39
|
+
if (!isAccessToken(token))
|
|
41
40
|
throw new RepoPathError("access_invalid");
|
|
42
41
|
if (!request.path.startsWith("/repos/") || request.path.includes("..") || /[\s#]/.test(request.path))
|
|
43
42
|
throw new RepoPathError("request_invalid");
|
package/build/node/repo-path.js
CHANGED
|
@@ -70,7 +70,7 @@ export class RepoBroker {
|
|
|
70
70
|
}
|
|
71
71
|
catch (error) {
|
|
72
72
|
this.held.delete(k);
|
|
73
|
-
this.log("repo.access", "refused", { ...ids, code: error
|
|
73
|
+
this.log("repo.access", "refused", error instanceof RepoPathError ? { ...ids, code: error.code, ...error.detail } : { ...ids, code: "access_invalid" });
|
|
74
74
|
throw error;
|
|
75
75
|
}
|
|
76
76
|
this.held.set(k, access);
|
package/git/credential-helper
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
# file descriptor 3, which Runner opened for that one Git command and closes when it ends. It never reads the token from
|
|
5
5
|
# an argument, the environment or a file, never writes it anywhere but Git's own pipe, and answers nothing for anything
|
|
6
6
|
# else. Every other action (store, erase) does nothing.
|
|
7
|
+
# Byte-wise, ASCII-only bracket ranges in the token check below, whatever the caller's locale (macOS bash 3.2 included).
|
|
8
|
+
LC_ALL=C
|
|
9
|
+
export LC_ALL
|
|
7
10
|
[ "$1" = "get" ] || exit 0
|
|
8
11
|
protocol=""
|
|
9
12
|
host=""
|
|
@@ -17,7 +20,10 @@ done
|
|
|
17
20
|
[ "$protocol" = "https" ] || exit 0
|
|
18
21
|
[ "$host" = "github.com" ] || exit 0
|
|
19
22
|
IFS= read -r token <&3 2>/dev/null || exit 0
|
|
23
|
+
# An installation token's characters only (`isAccessToken` in core/repository.ts): letters, digits, `_`, `.` and `-`, so a
|
|
24
|
+
# token can't add a line or a field to Git's credential protocol. At most 4096 of them.
|
|
20
25
|
case "$token" in
|
|
21
|
-
*[!A-Za-z0-
|
|
26
|
+
*[!A-Za-z0-9._-]* | "") exit 0 ;;
|
|
22
27
|
esac
|
|
28
|
+
[ "${#token}" -le 4096 ] || exit 0
|
|
23
29
|
printf 'username=x-access-token\npassword=%s\n' "$token"
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "podster",
|
|
3
|
-
"version": "0.0.1-test.
|
|
3
|
+
"version": "0.0.1-test.5",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "podster",
|
|
9
|
-
"version": "0.0.1-test.
|
|
9
|
+
"version": "0.0.1-test.5",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/claude-agent-sdk": "0.3.327",
|