Skip to content

Commit 7592cfc

Browse files
authored
fix(devtools-proxy-support): handle special characters in SSH URL correctly COMPASS-8254 (#469)
1 parent 904f3a4 commit 7592cfc

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

packages/devtools-proxy-support/src/ssh.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ describe('SSHAgent', function () {
4141
expect(setup.authHandler).to.have.been.calledOnceWith('foo', 'bar');
4242
});
4343

44+
it('handles special characters in username and password', async function () {
45+
setup.authHandler = sinon.stub().returns(true);
46+
agent = new SSHAgent({
47+
proxy: `ssh://foo%5E:ba%[email protected]:${setup.sshProxyPort}/`,
48+
});
49+
const fetch = createFetch(agent);
50+
await Promise.all([
51+
fetch('http://example.com/hello'),
52+
fetch('http://example.com/hello'),
53+
]);
54+
expect(setup.authHandler).to.have.been.calledOnceWith('foo^', 'ba&r');
55+
});
56+
4457
it('allows explicitly initializing the connection', async function () {
4558
setup.authHandler = sinon.stub().returns(true);
4659
agent = new SSHAgent({

packages/devtools-proxy-support/src/ssh.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ export class SSHAgent extends AgentBase implements AgentWithInitialize {
7878
const sshConnectConfig: ConnectConfig = {
7979
readyTimeout: 20000,
8080
keepaliveInterval: 20000,
81-
host: this.url.hostname,
81+
host: decodeURIComponent(this.url.hostname),
8282
port: +this.url.port || 22,
83-
username: this.url.username || undefined,
84-
password: this.url.password || undefined,
83+
username: decodeURIComponent(this.url.username) || undefined,
84+
password: decodeURIComponent(this.url.password) || undefined,
8585
privateKey: this.proxyOptions.sshOptions?.identityKeyFile
8686
? await fs.readFile(this.proxyOptions.sshOptions.identityKeyFile)
8787
: undefined,
@@ -92,7 +92,7 @@ export class SSHAgent extends AgentBase implements AgentWithInitialize {
9292
this.logger.emit('ssh:establishing-conection', {
9393
host: sshConnectConfig.host,
9494
port: sshConnectConfig.port,
95-
password: !!sshConnectConfig.passphrase,
95+
password: !!sshConnectConfig.password,
9696
privateKey: !!sshConnectConfig.privateKey,
9797
passphrase: !!sshConnectConfig.passphrase,
9898
});

0 commit comments

Comments
 (0)