Skip to content

Commit bacfb10

Browse files
committed
fix(mitm): disable upstream proxy for dns lookup
1 parent 56f924d commit bacfb10

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

mitm-socket/go/dialer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func Dial(addr string, connectArgs ConnectArgs, sessionArgs SessionArgs) (net.Co
2121
return nil, err
2222
}
2323

24-
if proxyUrl.Scheme == "socks5" {
24+
if proxyUrl.Scheme == "socks5" || proxyUrl.Scheme == "socks5h" {
2525
return DialAddrViaSock5Proxy(dialer, addr, proxyUrl)
2626
}
2727

mitm/lib/Dns.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export class Dns {
1717
}
1818

1919
public async lookupIp(host: string, retries = 3): Promise<string> {
20-
if (!this.dnsSettings.dnsOverTlsConnection || host === 'localhost' || net.isIP(host)) return host;
20+
// disable dns lookups when using a proxy
21+
if (this.requestSession.upstreamProxyUrl) return host;
22+
if (!this.dnsSettings.dnsOverTlsConnection || host === 'localhost' || net.isIP(host))
23+
return host;
2124

2225
try {
2326
// get cached (or in process resolver)

mitm/lib/DnsOverTlsSocket.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import IResolvablePromise from '@secret-agent/interfaces/IResolvablePromise';
44
import { createPromise } from '@secret-agent/commons/utils';
55
import MitmSocket from '@secret-agent/mitm-socket/index';
66
import { CanceledPromiseError } from '@secret-agent/commons/interfaces/IPendingWaitEvent';
7-
import IDnsSettings from "@secret-agent/interfaces/IDnsSettings";
7+
import IDnsSettings from '@secret-agent/interfaces/IDnsSettings';
88
import { addTypedEventListener, removeEventListeners } from '@secret-agent/commons/eventUtils';
99
import { IBoundLog } from '@secret-agent/interfaces/ILog';
1010
import Log from '@secret-agent/commons/Logger';
@@ -70,12 +70,7 @@ export default class DnsOverTlsSocket {
7070
keepAlive: true,
7171
debug: true,
7272
});
73-
if (this.dnsSettings.useUpstreamProxy) {
74-
const upstreamProxy = this.requestSession.upstreamProxyUrl;
75-
if (upstreamProxy) {
76-
this.mitmSocket.setProxyUrl(upstreamProxy);
77-
}
78-
}
73+
7974
await this.mitmSocket.connect(this.requestSession.requestAgent.socketSession, 10e3);
8075

8176
this.mitmSocket.socket.on('data', this.onData.bind(this));

puppet-chrome/lib/Browser.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,19 @@ export class Browser extends TypedEventEmitter<IBrowserEvents> implements IPuppe
150150

151151
private async onTargetCreated(event: Protocol.Target.TargetCreatedEvent) {
152152
const { targetInfo } = event;
153-
if (targetInfo.type === 'page' && !targetInfo.attached) {
154-
const context = this.browserContextsById.get(targetInfo.browserContextId);
155-
await context?.attachToTarget(targetInfo.targetId);
156-
}
157-
if (targetInfo.type === 'shared_worker') {
158-
const context = this.browserContextsById.get(targetInfo.browserContextId);
159-
await context?.attachToWorker(targetInfo);
153+
try {
154+
if (targetInfo.type === 'page' && !targetInfo.attached) {
155+
const context = this.browserContextsById.get(targetInfo.browserContextId);
156+
await context?.attachToTarget(targetInfo.targetId);
157+
}
158+
if (targetInfo.type === 'shared_worker') {
159+
const context = this.browserContextsById.get(targetInfo.browserContextId);
160+
await context?.attachToWorker(targetInfo);
161+
}
162+
} catch (error) {
163+
// target went away too quickly
164+
if (String(error).includes('No target with given id found')) return;
165+
throw error;
160166
}
161167
}
162168

0 commit comments

Comments
 (0)