mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-21 08:22:20 +02:00
## 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>
74 lines
2.9 KiB
TypeScript
74 lines
2.9 KiB
TypeScript
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);
|
|
}
|
|
});
|
|
});
|