Skip to content

Refuse a base URL with whitespace or control characters - #117

Open
vigninou-focas wants to merge 1 commit into
prooflinedev:mainfrom
vigninou-focas:fix/base-url-whitespace
Open

vigninou-focas wants to merge 1 commit into
prooflinedev:mainfrom
vigninou-focas:fix/base-url-whitespace

Conversation

@vigninou-focas

Copy link
Copy Markdown

Problem

baseUrl and PROOFLINE_BASE_URL go through origin(), which parses the value with new URL(). URL parsing quietly cleans up its input: it strips leading and trailing spaces and control characters, and it deletes tabs and newlines anywhere in the string. So on main these values are all accepted:

" https://proofline.sh"         -> https://proofline.sh
"https://proofline.sh\n"        -> https://proofline.sh
"https://proof\tline.sh"        -> https://proofline.sh

This affects anyone who sets the origin from a CI secret, a .env file, $(cat file) or a copy-paste. A stray trailing newline or space is the usual case. The client does not report the problem; it rewrites the value and sends the token to the rewritten origin. A value like https://proof\tline.sh reaches a host that differs from the string that was configured. The README says a value that is not an HTTPS origin or a loopback HTTP origin "is refused by name". The Python SDK refuses all of these values, and the MCP bridge refuses the ones with surrounding whitespace.

Change

origin() in src/transport.ts now refuses a value containing any character at or below U+0020 (space, tab, newline and the other C0 control characters) before parsing it. The refusal uses the existing message, so it names the setting and never repeats the value:

baseUrl must be an absolute HTTPS URL or loopback HTTP URL
PROOFLINE_BASE_URL must be an absolute HTTPS URL or loopback HTTP URL

The check sits beside URL.canParse(value) in one condition, replacing the try/catch around new URL(). The function's other checks (HTTPS or loopback HTTP, no credentials, path, query or fragment) are unchanged.

Only src/transport.ts and tests/http.test.mjs change. No generated code, schemas, API contracts, dependencies, README text or package version are modified.

Decisions

Parity with the Python SDK. proofline/_transport.py base_url() refuses any(ord(character) <= 32 for character in value), and test_token_environment_and_https_origin_rejection lists " https://example.com" among refused origins. This change applies the same rule, no more and no less. The MCP bridge also refuses a value with surrounding whitespace (raw !== raw.trim()).

Why not stricter. I looked at Unicode whitespace and invisible characters. NBSP, U+2028 and DEL are already refused by URL parsing on main. A byte-order mark, a soft hyphen or a zero-width space inside the host is still accepted and removed by hostname normalisation. Refusing those would make the TypeScript client stricter than the Python SDK, so I left them out; if the clients should refuse them, that is a change for both SDKs together.

localhost is left alone. The CLI's origin.rs accepts http://localhost, while the Python SDK and the MCP bridge accept only literal loopback IP addresses. The clients disagree, so this change does not pick a side; http://localhost, http://127.0.0.1 and http://[::1] behave as before.

Follows #50. The check reuses the origin validation that #50 introduced for PROOFLINE_BASE_URL: the same baseUrl must be / PROOFLINE_BASE_URL must be prefixes, no value in the message, and an empty variable still counts as unset. A value that is only whitespace was already refused by name and still is.

Verification

The test an unusable PROOFLINE_BASE_URL is refused by name without echoing its value is extended and renamed to an unusable baseUrl or PROOFLINE_BASE_URL is refused by name without echoing its value, since it now covers both settings. It adds four values, each checked for the option and for the variable, asserting a TypeError whose message starts with the setting's name and does not contain the value:

" https://customer.example"     leading space
"https://customer.example "     trailing space
"https://customer.example\n"    trailing newline
"https://custo\tmer.example"    tab inside the host

On main's src/transport.ts, all eight checks (four values, two settings) are accepted and the test fails:

✖ an unusable baseUrl or PROOFLINE_BASE_URL is refused by name without echoing its value
  AssertionError [ERR_ASSERTION]: Missing expected exception.

With the change, it passes. The test count stays at 106 because the cases extend an existing test.

The branch is one commit on main at ec8dd5d. I ran the steps of .github/workflows/ci.yml in order under Node 22, with npm 12.2.0 and pnpm 11.25.0 installed as in CI. Every step exited 0:

pnpm install --frozen-lockfile --ignore-scripts   39 packages, lockfile unchanged
pnpm generate        no change to src/schema.d.ts or src/operations.ts
pnpm lint            Checked 12 files. No fixes applied.
pnpm typecheck       no output
node check-claims.mjs   no output
pnpm build           no output
pnpm test            tests 106, pass 106, fail 0, cancelled 0, skipped 0
npm pack --ignore-scripts   proofline-sdk-10.6.0.tgz, 21 files

Notes on that run: Node was v22.23.4 (CI pins v22.23.2). pnpm 11.25.0 switches to 12.19.0 because of the packageManager field, so the pnpm steps ran on 12.19.0, as they do in CI. Because the change was not yet committed, I checked generation freshness by comparing the working-tree diff before and after pnpm generate instead of git diff --exit-code. The same checks also pass on Node 24.22.2.

Development environment

The work was done in an isolated GitHub Codespace. Before running anything, I audited the repository for supply-chain and local-machine risks: git hooks, scripts that touch the network or filesystem, CI workflows, lockfile resolutions and integrity hashes, and text addressed to AI agents. Dependencies were installed with pnpm install --frozen-lockfile --ignore-scripts; no dependency was added. The CI versions of npm and pnpm were installed into a temporary directory, not globally, and no repository file was changed to run under Node 22.

Not verified

Nothing was run against proofline.sh; all HTTP tests use the existing local server fixture. GitHub Actions has not run on this branch, and Node 22 was v22.23.4 rather than CI's v22.23.2.

All prompts from this development session are included below in a hidden comment, as AGENTS.md requires.

🤖 Generated with Claude Code

URL parsing strips surrounding whitespace and deletes tabs and newlines,
so " https://proofline.sh", "https://proofline.sh\n" or a host containing
a tab were accepted and silently rewritten. Refuse any character at or
below U+0020, as the Python SDK does, naming baseUrl or
PROOFLINE_BASE_URL without echoing the value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants