Skip to content

cli: return 400 on malformed request URLs and invalid /v1/models encoding - #436

Open
Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/http-malformed-url-and-model-encoding
Open

Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/http-malformed-url-and-model-encoding

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 3, 2026

Copy link
Copy Markdown

Summary

  • cli/lib/http.js (request listener): Move new URL(req.url, "http://x") inside the request try block and convert TypeError into bad("invalid request URL") (400 Bad Request). Previously, new URL(...) ran before try inside the async handler, turning malformed request targets (e.g. GET http://[ HTTP/1.1) into unhandled promise rejections instead of a 400 response.
  • cli/lib/http.js (models()): Wrap decodeURIComponent(rest) in try/catch and return bad("invalid URL encoding in model id") (400 Bad Request, in either OpenAI or Anthropic error shape depending on headers) instead of letting URIError fall through as a 500 server error (matching cli/lib/responses.js's guarded decodeURIComponent).

Tests

  • Added regression test in cli/test/http_test.mjs covering GET /v1/models/%E0%A4%A (OpenAI and Anthropic error shapes) and a raw TCP request with GET http://[ HTTP/1.1 asserting 400 Bad Request and zero unhandledRejection events. Confirmed the test failed before the fix and passed after.
  • Ran:
    • node --check cli/lib/http.js cli/test/http_test.mjs
    • node --test cli/test/*_test.mjs (174 passed, 0 failed, 0 skipped)
    • node --test packages/room-node/test/*_test.mjs packages/openclaw/test/*_test.mjs (213 passed, 6 skipped, 0 failed)
    • npm run test:runtime (6/6 runtime checks passed, 172 frames)

@Pybsama
Pybsama requested a review from Nehanth as a code owner December 3, 2026 20:40
@vercel

vercel Bot commented Dec 3, 2026

Copy link
Copy Markdown

@Pybsama is attempting to deploy a commit to the nehanth's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant