Repository navigation
Description
[agent] Found by the architecture refactor routine, on main at cfc870f.
Problem
A host that is not the patch service and answers 403 or 401 makes socket-patch tell the user to buy a plan, or that their token is invalid. A web filter's block page, a WAF, a login gateway in front of a mistyped --proxy-url: each is such a host.
- With no token,
get <uuid>of a free patch says "This patch requires a paid Socket plan … Upgrade to a paid Socket plan" and exits 0 (paid_required). scan,get <purl>,get CVE-…,show,repairand anapplythat has a blob to download say "This patch is only available to paid subscribers. Sign up at https://socket.dev to access paid patches."- A
401page gives "Unauthorized: Invalid API token" to a run that has no token. - With a token, and a filter that blocks
api.socket.devalone,scanblames the token or the plan, falls back to the free patches and exits 0 withstatus: success. An organization that pays gets the free patches only.
The same page with any other 4xx status gets the error the contract asks for: it names the host that answered, quotes the page and names the setting to check.
Evidence
A server that answers every request with one status and a block page (20 lines of Python, below), named by SOCKET_PROXY_URL. The binary is built from main; SOCKET_TELEMETRY_DISABLED=1 SOCKET_NO_CONFIG=1 are set and no token is.
$ SOCKET_PROXY_URL=http://127.0.0.1:19000 socket-patch get aaaaaaaa-0000-4000-8000-000000000002 --mode agent --yes # 403 + the page
This patch requires a paid Socket plan.
Patch: aaaaaaaa-0000-4000-8000-000000000002
Upgrade to a paid Socket plan to access all patches: https://socket.dev/pricing # exit 0
$ SOCKET_PROXY_URL=http://127.0.0.1:19000 socket-patch scan --mode agent --yes # 403 + the page
Error: The API query failed: Forbidden: This patch is only available to paid subscribers. Sign up at https://socket.dev to access paid patches. # exit 1
$ SOCKET_PROXY_URL=http://127.0.0.1:19001 socket-patch scan --mode agent --yes # 401 + the page
Error: The API query failed: Unauthorized: Invalid API token # exit 1
$ SOCKET_PROXY_URL=http://127.0.0.1:19002 socket-patch scan --mode agent --yes # 404 + the page
Error: The API query failed: API request failed with status 404: 127.0.0.1:19002 did not answer like the Socket patch API (<html><head><title>Access Denied</title></head><body><h1>Blocked by corporate policy</h1><p>Category: uncategorized. Tic...) — check --proxy-url / SOCKET_PROXY_URL # exit 1
The same page behind a TLS-inspecting forward proxy (HTTPS_PROXY, its CA in SSL_CERT_FILE), with the default service URLs, by status and body:
| The answer | scan |
get <uuid> |
|---|---|---|
| 400, 402, 404, 407 or 451 with the page | exit 1: … status <n>: patches-api.socket.dev did not answer like the Socket patch API (<html>…) — check --proxy-url / SOCKET_PROXY_URL |
exit 1, the same error |
403 with the page, with another service's JSON ({"status":403,"error":"Forbidden","path":…}), or with no body |
exit 1: "This patch is only available to paid subscribers. Sign up at https://socket.dev …" | exit 0: "This patch requires a paid Socket plan. … Upgrade …"; under --json, status: paidRequired |
| 401 with the page | exit 1: "Unauthorized: Invalid API token" | exit 1, the same |
The other commands on the 403 page, with no token:
$ socket-patch show aaaaaaaa-0000-4000-8000-000000000002
Error: patch aaaaaaaa-… needs a paid Socket plan, or access this token does not have (Forbidden: This patch is only available to paid subscribers. …)
$ socket-patch get pkg:npm/left-pad@1.3.0 # and: get CVE-2026-0002
Error: Forbidden: This patch is only available to paid subscribers. Sign up at https://socket.dev to access paid patches.
$ socket-patch repair # .socket/blobs is not committed
Error: Failed to download 6 blobs
- 22c2356a8a3c...: Forbidden: This patch is only available to paid subscribers. Sign up at https://socket.dev to access paid patches.
$ socket-patch apply # the same project after a fresh install; exit 1
Failed to download 6 blobs:
- 22c2356a8a3c...: Forbidden: This patch is only available to paid subscribers. …
$ socket-patch scan # hosted mode; exit 1
Error: The API query failed: Forbidden: This patch is only available to paid subscribers. …
With SOCKET_API_TOKEN and SOCKET_ORG_SLUG set:
# the filter answers both hosts with the 403 page
Warning: authenticated API returned Forbidden: Access denied. This may be a paid patch or you may not have access to this organization.; falling back to public patch API proxy (free patches only).
Error: The API query failed: Forbidden: This patch is only available to paid subscribers. Sign up at https://socket.dev to access paid patches. # exit 1
# the filter answers api.socket.dev alone, with the 403 page
Applied 6 patches.
Warning: authenticated API returned Forbidden: Access denied. This may be a paid patch or you may not have access to this organization.; falling back to public patch API proxy (free patches only). # exit 0; --json: "status": "success"
# the same with the 401 page
Applied 6 patches.
Warning: authenticated API returned Unauthorized: Invalid API token; falling back to public patch API proxy (free patches only). # exit 0
In the second run the public service saw 13 requests and none carried the token: the six patches are the free ones.
Cause
CLI_CONTRACT.md, under "'No patches' needs an answer":
The service answers an error in its own JSON shape […] and that shape is how its answer is told apart from another host's (a mistyped
--proxy-url/--api-url, a captive portal, a forward proxy or WAF answering in its place): […] a4xxthe service did not write are errors that name the host that answered and the setting to check.
354ab99 (#2052, its part "Report 'no patches' only when the patch service answered") added that rule to core api/client.rs as service_error_message and misdirected_error, and applied it to a 200, a 404, a 400 and every other 4xx. The comment on service_error_message (lines 101 to 109) gives the reason: "a mistyped URL, a captive portal and a forward proxy all answer with a status the service also uses, so the status alone cannot say whether the question about patches was answered."
401 and 403 are still decided by the status alone. classify_auth_error (line 3013) takes no body, and each of its five callers asks it before the body is read:
| Line | Function | Requests |
|---|---|---|
| 939 | handle_json_response |
every JSON route: views, searches, the authenticated batch |
| 1344 | proxy_batch_post |
the token-less batch |
| 1590 | fetch_binary |
blobs |
| 2030 | request_vendor_references_once |
hosted and vendored package references |
| 2190 | serve_get_once |
the vendored artifact |
is_fallback_candidate (line 2996) then reads either error as "the service refused this token", which is the fallback in the last three runs above.
Planned fix
One rule in api/client.rs, used by all five callers: a 401 or 403 is the service's refusal when its body is the service's own (service_error_message), and otherwise it is misdirected_error, as for every other 4xx: API request failed with status 403: <host> did not answer like the Socket patch API (<start of the body>) — check --proxy-url / SOCKET_PROXY_URL. A refusal the service did not write is then not a fallback candidate, so a blocked api.socket.dev fails the run instead of dropping it to the free patches.
One fact is needed from Socket's backend before the fix is written: the body of its own 401 and 403. The contract says the service answers errors in its JSON shape. The tests here stand in for those refusals with no body or with plain text (ResponseTemplate::new(401), new(403) and set_body_string("Unauthorized") in core api/client.rs, core tests/binary_fetch_error_classification_e2e.rs and the CLI's tests/cli/api_client_errors_e2e.rs), and this sandbox has no route to the service. If a real refusal can arrive with no body, a bodiless 401 / 403 stays the service's, as a bodiless 404 does for the callers the service has already answered, and only a body that is not the service's is another host's.
Tests: one row per caller with the block page on 401 and 403 (red on main), and the existing refusal tests given the service's body.
The block page server
#!/usr/bin/env python3
"""block.py <port> <status>: answers every request with <status> and a web filter's block page."""
import sys
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
port, status = int(sys.argv[1]), int(sys.argv[2])
BODY = b"<html><head><title>Access Denied</title></head><body><h1>Blocked by corporate policy</h1><p>Category: uncategorized. Ticket: NET-4242</p></body></html>\n"
class H(BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"
def log_message(self, *a): pass
def any(self):
n = int(self.headers.get("Content-Length", 0) or 0)
if n: self.rfile.read(n)
self.send_response(status); self.send_header("Content-Type", "text/html")
self.send_header("Content-Length", str(len(BODY))); self.end_headers()
if self.command != "HEAD": self.wfile.write(BODY)
do_GET = do_POST = do_HEAD = do_PUT = any
ThreadingHTTPServer(("127.0.0.1", port), H).serve_forever()The project is an npm install of six packages (any will do: the run never gets past the first request). For repair and apply, a project that an earlier scan patched, with .socket/blobs removed.
Generated by Claude Code
Activity
refactor: #2365 and #2366 filed; proxies ran