Skip to content

fix(devtools-proxy-support): handle special characters in SSH URL correctly COMPASS-8254 #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/devtools-proxy-support/src/ssh.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ describe('SSHAgent', function () {
expect(setup.authHandler).to.have.been.calledOnceWith('foo', 'bar');
});

it('handles special characters in username and password', async function () {
setup.authHandler = sinon.stub().returns(true);
agent = new SSHAgent({
proxy: `ssh://foo%5E:ba%[email protected]:${setup.sshProxyPort}/`,
});
const fetch = createFetch(agent);
await Promise.all([
fetch('http://example.com/hello'),
fetch('http://example.com/hello'),
]);
expect(setup.authHandler).to.have.been.calledOnceWith('foo^', 'ba&r');
});

it('allows explicitly initializing the connection', async function () {
setup.authHandler = sinon.stub().returns(true);
agent = new SSHAgent({
Expand Down
8 changes: 4 additions & 4 deletions packages/devtools-proxy-support/src/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export class SSHAgent extends AgentBase implements AgentWithInitialize {
const sshConnectConfig: ConnectConfig = {
readyTimeout: 20000,
keepaliveInterval: 20000,
host: this.url.hostname,
host: decodeURIComponent(this.url.hostname),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see how this would be easy to miss.

port: +this.url.port || 22,
username: this.url.username || undefined,
password: this.url.password || undefined,
username: decodeURIComponent(this.url.username) || undefined,
password: decodeURIComponent(this.url.password) || undefined,
privateKey: this.proxyOptions.sshOptions?.identityKeyFile
? await fs.readFile(this.proxyOptions.sshOptions.identityKeyFile)
: undefined,
Expand All @@ -92,7 +92,7 @@ export class SSHAgent extends AgentBase implements AgentWithInitialize {
this.logger.emit('ssh:establishing-conection', {
host: sshConnectConfig.host,
port: sshConnectConfig.port,
password: !!sshConnectConfig.passphrase,
password: !!sshConnectConfig.password,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😭

Copy link
Collaborator Author

@addaleax addaleax Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair, this bit is unrelated to the bug itself, but still, yeah, not my smartest move 😅

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I see now it is just in a logging event 👍

privateKey: !!sshConnectConfig.privateKey,
passphrase: !!sshConnectConfig.passphrase,
});
Expand Down
Loading