mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-22 11:54:35 +01:00
feat(codex-local): give each Codex account its own home and path secret (#12709)
## Thinking Path > - Paperclip is the control plane for companies that use AI agents for work > - Local adapters connect Paperclip agents to provider command line tools > - The Codex adapter stores login data in a shared company home > - A shared home cannot keep credentials for more than one Codex account > - This pull request gives each account a safe home and a matching company secret > - The benefit is that one company can use multiple Codex accounts at the same time ## Linked Issues or Issue Description **Problem or motivation** A company can hold only one Codex subscription credential because device login uses one shared home. A second account cannot log in without replacing or conflicting with the first credential. **Proposed solution** This change validates the vendor account identifier, stores each credential in its own home, and creates a company secret that points to that home. Repeat login calls return success when the matching secret already exists. **Roadmap alignment** The change supports the roadmap goal for centrally managed secrets with scoped access and audited resolution. **Additional context** The security review returned approve with no blocking finding. The branch adds shared account-handle validation and tests for device login and the Codex local adapter. ## What Changed - Add strict allowlist validation for Codex account handles. - Store each Codex account credential in a separate home under the Codex cache root. - Verify that the resolved account home stays inside the cache root. - Create the `CODEX_HOME_<handle>` company secret for each account. - Keep repeat and concurrent login calls safe and idempotent. - Add shared helper and route, adapter, and validation tests. ## Verification - `pnpm --filter @paperclipai/adapter-codex-local test` passes with 343 tests. - `pnpm --filter @paperclipai/server test src/__tests__/agent-device-login-routes.test.ts` passes with 25 tests. - The adapter suite passes with 23 tests. - The shared package and Codex adapter typechecks pass. - Continuous integration must pass on every check before merge. ## Risks The account handle becomes part of a directory path and secret name. The strict allowlist and root containment check reduce path traversal risk. Existing single-account homes remain unchanged unless a new device login creates an account-specific home. ## Model Used OpenAI GPT-5 (exact runtime model ID: gpt-5), with tool use and code execution. The runtime context window is not exposed in this run. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
dfdfc8664e
commit
9064cfd09e
15 files changed
+3261
-711
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { ACCOUNT_HANDLE_MAX_LENGTH, toAccountHandle } from "./account-handle.js";
|
||||
import { createUserSecretDefinitionSchema } from "./validators/secret.js";
|
||||
|
||||
describe("toAccountHandle", () => {
|
||||
it("returns the value for a plain identifier", () => {
|
||||
expect(toAccountHandle("acct-42")).toBe("acct-42");
|
||||
});
|
||||
|
||||
it("returns null for a value that holds a space, such as \"a b\"", () => {
|
||||
expect(toAccountHandle("a b")).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for a value with surrounding whitespace instead of trimming it", () => {
|
||||
// Trimming a value before validation would let " acct-42" and "acct-42"
|
||||
// resolve to the same handle. Two distinct identifiers must never share
|
||||
// one handle, so surrounding whitespace is a rejection, not something to
|
||||
// strip.
|
||||
expect(toAccountHandle(" acct-42")).toBeNull();
|
||||
expect(toAccountHandle("acct-42 ")).toBeNull();
|
||||
expect(toAccountHandle(" acct-42 ")).toBeNull();
|
||||
expect(toAccountHandle("\tacct-42\n")).toBeNull();
|
||||
// The plain identifier with no surrounding whitespace still passes.
|
||||
expect(toAccountHandle("acct-42")).toBe("acct-42");
|
||||
});
|
||||
|
||||
it("returns null for an empty string", () => {
|
||||
expect(toAccountHandle("")).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for a value that holds a plus sign, such as \"a+b\"", () => {
|
||||
expect(toAccountHandle("a+b")).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for a value that holds a colon, such as \"a:b\"", () => {
|
||||
expect(toAccountHandle("a:b")).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for a value longer than 100 characters", () => {
|
||||
const tooLong = "a".repeat(ACCOUNT_HANDLE_MAX_LENGTH + 1);
|
||||
expect(toAccountHandle(tooLong)).toBeNull();
|
||||
const atLimit = "a".repeat(ACCOUNT_HANDLE_MAX_LENGTH);
|
||||
expect(toAccountHandle(atLimit)).toBe(atLimit);
|
||||
});
|
||||
|
||||
it("returns null for \".\" and for \"..\"", () => {
|
||||
expect(toAccountHandle(".")).toBeNull();
|
||||
expect(toAccountHandle("..")).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for a value that starts with a hyphen, such as \"-rf\"", () => {
|
||||
expect(toAccountHandle("-rf")).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for a value that holds a shell metacharacter, such as \"$(id)\"", () => {
|
||||
expect(toAccountHandle("$(id)")).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null for a value that holds a path separator or a NUL byte", () => {
|
||||
expect(toAccountHandle("a/b")).toBeNull();
|
||||
expect(toAccountHandle("a\\b")).toBeNull();
|
||||
expect(toAccountHandle("a\0b")).toBeNull();
|
||||
});
|
||||
|
||||
it("every accepted handle also passes the secret key schema", () => {
|
||||
const candidates = ["acct-42", "acct_42", "ACCT.42", "a".repeat(ACCOUNT_HANDLE_MAX_LENGTH)];
|
||||
for (const candidate of candidates) {
|
||||
const handle = toAccountHandle(candidate);
|
||||
expect(handle).not.toBeNull();
|
||||
expect(createUserSecretDefinitionSchema.shape.key.safeParse(handle).success).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
// A canonical account handle names one login account inside one company. Two
|
||||
// downstream sinks each guard the raw account identifier with a different
|
||||
// validator: a directory-segment denylist, and the secret-key allowlist
|
||||
// (`packages/shared/src/validators/secret.ts`). `toAccountHandle` accepts a
|
||||
// value only when it satisfies both, so one handle can safely name both a
|
||||
// directory and a secret.
|
||||
|
||||
/** The longest accepted account handle. The secret key limit is 120
|
||||
* characters, and the longest name prefix a caller adds is `CODEX_HOME_` at
|
||||
* 11 characters, so 100 leaves headroom. */
|
||||
export const ACCOUNT_HANDLE_MAX_LENGTH = 100;
|
||||
|
||||
// The same character class the secret key schema uses.
|
||||
const ACCOUNT_HANDLE_PATTERN = /^[a-zA-Z0-9_.-]+$/;
|
||||
|
||||
/**
|
||||
* Converts a raw account identifier into a safe account handle. Returns
|
||||
* `null` when the value cannot become one instead of throwing, so a caller
|
||||
* decides how to fail the operation.
|
||||
*
|
||||
* The identifier is the account's identity key: it names one directory and
|
||||
* one secret, so two distinct identifiers must never resolve to the same
|
||||
* handle. A caller must never normalize the value before this check (for
|
||||
* example, by trimming it) — normalizing first can alias a distinct
|
||||
* identifier onto an already-claimed handle and let a login accept a
|
||||
* different account's credential home as its own.
|
||||
*
|
||||
* An input becomes a handle only when every rule below is true:
|
||||
*
|
||||
* - It carries no leading or trailing whitespace.
|
||||
* - It matches `/^[a-zA-Z0-9_.-]+$/`.
|
||||
* - It is {@link ACCOUNT_HANDLE_MAX_LENGTH} characters or shorter.
|
||||
* - It is neither `.` nor `..`.
|
||||
* - It does not start with `-` (a leading `-` reads as a command-line option).
|
||||
*/
|
||||
export function toAccountHandle(rawAccountId: string): string | null {
|
||||
if (typeof rawAccountId !== "string" || rawAccountId.length === 0) return null;
|
||||
if (rawAccountId.trim() !== rawAccountId) return null;
|
||||
if (!ACCOUNT_HANDLE_PATTERN.test(rawAccountId)) return null;
|
||||
if (rawAccountId.length > ACCOUNT_HANDLE_MAX_LENGTH) return null;
|
||||
if (rawAccountId === "." || rawAccountId === "..") return null;
|
||||
if (rawAccountId.startsWith("-")) return null;
|
||||
return rawAccountId;
|
||||
}
|
||||
@@ -2726,3 +2726,4 @@ export {
|
||||
isPaperclipDevRunnerCommand,
|
||||
rewriteUrlHostToLoopback,
|
||||
} from "./runtime-exposure/loopback-bind.js";
|
||||
export { ACCOUNT_HANDLE_MAX_LENGTH, toAccountHandle } from "./account-handle.js";
|
||||
Reference in new issue
Block a user