Skip to content

Commit 724b114

Browse files
anandgupta42claude
andcommitted
fix: address PR #794 round-2 review feedback (cubic P1 + CR nits)
cubic flagged a real P1 on the previous round's commit and CodeRabbit posted a few low-value nits worth picking up while we're here. P1 (cubic) — `Telemetry.maskString` URL regex missed URLs carrying basic-auth userinfo before the host. `https://admin:[email protected]/x` fell through unredacted because the regex started with the host alternation. Added an optional `(?:[^\/\s@]+@)?` userinfo prefix so the whole URL — credentials + host — is captured into `<internal-host>`. CR quick wins: - Hoisted the `Telemetry` import to the top of the adversarial test file (mid-file imports work in Bun but tooling that scans headers miss them). - Tightened the `/models` hint test to assert the full canonical string ``Run `altimate models` to see available models.`` so docs / changelog / code can't quietly diverge again. Defense-in-depth from CR nits: - Added `0.0.0.0` (any-interface bind) to maskInternalHost — shows up in misconfigured proxy URLs and is functionally internal. - Added a one-line comment to the silent `catch {}` in isOpenAiErrorRetryable so a future refactor doesn't "fix" it into something that throws on malformed JSON. Also added 2 new adversarial tests pinning the userinfo+host case and the `0.0.0.0` case (240/240 across the 5 affected files, up from 238). Deferred to v0.7.2: extracting `makeAPICallError` to a shared fixture (refactor, scope creep), reusing `codeFromBody` in `isOpenAiErrorRetryable` (signature change), IPv4-mapped IPv6 (`::ffff:10.0.0.1`) coverage, byte-vs-char `RESPONSE_BODY_CAP` rename. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent fd28dd3 commit 724b114

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

‎packages/opencode/src/altimate/telemetry/index.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,11 @@ export namespace Telemetry {
10731073
// don't survive past the redaction marker. Over-masking is the correct
10741074
// failure mode here.
10751075
.replace(
1076-
/\bhttps?:\/\/(?:localhost|127\.\d+\.\d+\.\d+|10\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|172\.(?:1[6-9]|2\d|3[01])\.\d+\.\d+|169\.254\.\d+\.\d+|\[(?:::1|fc[0-9a-f]{2}:[^\]]*|fd[0-9a-f]{2}:[^\]]*|fe80:[^\]]*)\]|[A-Za-z0-9.-]+\.(?:local|internal|localhost))(?::\d+)?[\w/.?=&%+#,;~!*'()@:-]*/gi,
1076+
// `(?:[^\/\s@]+@)?` allows optional basic-auth userinfo
1077+
// (`user:pass@`) before the host so URLs like
1078+
// `https://admin:[email protected]/x` are still recognized as internal
1079+
// and redacted whole. The credential goes with the host into <internal-host>.
1080+
/\bhttps?:\/\/(?:[^\/\s@]+@)?(?:localhost|127\.\d+\.\d+\.\d+|10\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|172\.(?:1[6-9]|2\d|3[01])\.\d+\.\d+|169\.254\.\d+\.\d+|0\.0\.0\.0|\[(?:::1|fc[0-9a-f]{2}:[^\]]*|fd[0-9a-f]{2}:[^\]]*|fe80:[^\]]*)\]|[A-Za-z0-9.-]+\.(?:local|internal|localhost))(?::\d+)?[\w/.?=&%+#,;~!*'()@:-]*/gi,
10771081
"<internal-host>",
10781082
)
10791083
.replace(/'(?:[^'\\]|\\.)*'/g, "?")

‎packages/opencode/src/provider/error.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ export namespace ProviderError {
3636
try {
3737
const body = e.responseBody ? JSON.parse(e.responseBody) : null
3838
if (body?.error?.code === "model_not_found") return false
39-
} catch {}
39+
} catch {
40+
// Malformed JSON on a 404 falls through to "force retryable" below —
41+
// intentional; some providers emit non-JSON 404 bodies for transient
42+
// model availability blips and those should still retry.
43+
}
4044
}
4145
// altimate_change end
4246
// openai sometimes returns 404 for models that are actually available
@@ -258,6 +262,7 @@ export namespace ProviderError {
258262
u.password = ""
259263
const isInternal =
260264
host === "localhost" ||
265+
host === "0.0.0.0" || // any-interface bind, often misconfigured proxy
261266
host.endsWith(".local") ||
262267
host.endsWith(".internal") ||
263268
host.endsWith(".localhost") ||

‎packages/opencode/test/skill/release-v0.7.1-adversarial.test.ts‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import { describe, test, expect } from "bun:test"
1717
import { ProviderError } from "../../src/provider/error"
18+
import { Telemetry } from "../../src/altimate/telemetry"
1819
import { APICallError } from "ai"
1920

2021
function makeAPICallError(opts: {
@@ -380,7 +381,9 @@ describe("parseAPICallError — /models hint on model_not_found", () => {
380381
expect(result.type).toBe("api_error")
381382
if (result.type === "api_error") {
382383
expect(result.message).toContain("does not exist")
383-
expect(result.message).toContain("altimate models")
384+
// Pin the canonical hint text exactly so docs / changelog / code can't
385+
// diverge silently. This string is the single source of truth.
386+
expect(result.message).toContain("Run `altimate models` to see available models.")
384387
}
385388
})
386389

@@ -698,8 +701,6 @@ describe("parseAPICallError — metadata.url masking for internal hosts", () =>
698701
// Fix F — maskString email + internal-host masking
699702
// ---------------------------------------------------------------------------
700703

701-
import { Telemetry } from "../../src/altimate/telemetry"
702-
703704
describe("Telemetry.maskString — email and internal-host patterns", () => {
704705
test("email addresses are masked to <email>", () => {
705706
const out = Telemetry.maskString("[email protected] is not authorized")
@@ -761,4 +762,22 @@ describe("Telemetry.maskString — email and internal-host patterns", () => {
761762
expect(out).not.toContain("#frag")
762763
expect(out).toContain("<internal-host>")
763764
})
765+
766+
test("internal URL with basic-auth userinfo is fully redacted (cubic P1 regression)", () => {
767+
// Pre-fix: regex started with the host alternation, missing `user:pass@`
768+
// prefix, so `https://admin:[email protected]/x` did NOT match — basic-auth
769+
// creds + internal host both leaked. Now matches via the optional
770+
// `(?:[^\/\s@]+@)?` group.
771+
const out = Telemetry.maskString("Cannot reach https://admin:[email protected]/secret")
772+
expect(out).not.toContain("hunter2")
773+
expect(out).not.toContain("admin:")
774+
expect(out).not.toContain("10.0.0.5")
775+
expect(out).toContain("<internal-host>")
776+
})
777+
778+
test("0.0.0.0 (any-interface bind) is masked", () => {
779+
const out = Telemetry.maskString("Probe failed http://0.0.0.0:8080/")
780+
expect(out).not.toContain("0.0.0.0")
781+
expect(out).toContain("<internal-host>")
782+
})
764783
})

0 commit comments

Comments
 (0)