Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
Take a proxy password with a bare % as written instead of failing every command (#692)
Omkar Chebale104cc4be4c16
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 45104457..fc493d2d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,15 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.## Unreleased+### A proxy password containing `%` no longer stops every shell command++A proxy password with a `%` that does not start an escape, such as `p%zz`, made decoding it throw.+- In the computer's shell, which strips proxy credentials before every command, every `/exec`+ failed as a result.+- Resolving a Bot's egress proxy failed the same way.++Such a password is now taken as written, and it is still kept out of the shell's environment.+### Revoking a credential twice says so, instead of answering a server errorRevoking a credential that was already revoked, or that does not exist, now answers 404 with thediff --git a/agent-computer/src/egress.ts b/agent-computer/src/egress.tsindex 02f7e085..7fff9bc3 100644--- a/agent-computer/src/egress.ts+++ b/agent-computer/src/egress.ts@@ -111,8 +111,8 @@ export function splitProxyCredentials(raw: string): Egress {}}- const username = url.username ? decodeURIComponent(url.username) : undefined;- const password = url.password ? decodeURIComponent(url.password) : undefined;+ const username = url.username ? decodeUserinfo(url.username) : undefined;+ const password = url.password ? decodeUserinfo(url.password) : undefined;url.username = "";url.password = "";@@ -123,6 +123,23 @@ export function splitProxyCredentials(raw: string): Egress {};}+/**+ * A proxy username or password, percent-decoded where it was percent-encoded.+ *+ * A `%` not followed by two hex digits is a character somebody typed, not an escape, and+ * `decodeURIComponent` throws `URIError` on it. That escaped every caller here, which only catches+ * `TypeError`, and since the shell strips credentials from the proxy variables before every+ * command, one such password made every `/exec` fail. As written is what was meant.+ */+function decodeUserinfo(value: string): string {+ try {+ return decodeURIComponent(value);+ } catch (e) {+ if (e instanceof URIError) return value;+ throw e;+ }+}+/*** The label for a Bot's egress, for people and for the admin list.*diff --git a/agent-computer/tests/egress.test.ts b/agent-computer/tests/egress.test.tsindex c5a57b28..a4f7f4f5 100644--- a/agent-computer/tests/egress.test.ts+++ b/agent-computer/tests/egress.test.ts@@ -91,6 +91,22 @@ describe("resolving a Bot's proxy", () => {expect(proxy?.server).toBe("proxy.internal:8080");});+ test.each([+ ["http://bot:p%[email protected]:8080", "http://proxy.internal:8080"],+ ["bot:p%[email protected]:8080", "proxy.internal:8080"],+ ])("a password with a bare %% is kept as written: %s", (raw, server) => {+ // A `%` that does not start an escape is a character somebody typed. Decoding it threw a+ // URIError, which nothing here caught, so every command the shell ran failed along with it.+ expect(egressFor("sales", { EGRESS_PROXY_SALES: raw })).toEqual({+ server,+ username: "bot",+ password: "p%zz",+ });+ expect(egressLabel("sales", { EGRESS_PROXY_SALES: raw })).toBe(+ "proxy.internal:8080",+ );+ });+test("something that is not addressable at all is still passed through", () => {expect(egressFor("sales", { EGRESS_PROXY_SALES: "::::" })).toEqual({server: "::::",diff --git a/agent-computer/tests/shell.test.ts b/agent-computer/tests/shell.test.tsindex 959c3506..2533dd76 100644--- a/agent-computer/tests/shell.test.ts+++ b/agent-computer/tests/shell.test.ts@@ -126,6 +126,21 @@ describe("what a command inherits", () => {expect(JSON.stringify(env)).not.toContain("p@ss");});+ test("a proxy password with a bare % is still stripped, and does not stop the command", () => {+ // Decoding `p%zz` threw a URIError past the redaction, so building the environment failed+ // and every command with it. It must not fail, and it must not fall back to passing the password.+ const env = environmentForCommand(+ source({+ HTTP_PROXY: "http://bot:p%[email protected]:8080",+ HTTPS_PROXY: "bot:p%[email protected]:8443",+ }),+ workspaceHome,+ );+ expect(env.HTTP_PROXY).toBe("http://proxy.internal:8080");+ expect(env.HTTPS_PROXY).toBe("proxy.internal:8443");+ expect(JSON.stringify(env)).not.toContain("p%zz");+ });+test("a proxy URL's userinfo does not pass when it was written without a scheme", () => {// `HTTPS_PROXY=bot:[email protected]:8443` is a shape curl and wget accept. `new URL` reads// it as the scheme `bot:` and a path, so the redaction above found no userinfo to strip and the