-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Request filtering in main process2 #16264
base: develop
Are you sure you want to change the base?
Conversation
0d4c182
to
e9c5d25
Compare
4c3b80a
to
7c52991
Compare
🚀 Expo preview is ready!
|
7c52991
to
80d2247
Compare
e9c5d25
to
b5528cc
Compare
2023d2c
to
053106c
Compare
053106c
to
685fb18
Compare
return whitelist.some( | ||
whitelistedUrl => | ||
whitelistedUrl === hostname || | ||
// Todo: this .endsWith() seems fishy to me, why we need this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan to try to remove this together with sldev in next PR and we'll see what breaks 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this fn is called only with hostname extracted from the url, then we are safe that you cannot loophole it like that:
http://scammy-url.net?uselessParam=trezor.io
I think this is necessary to allows subdomains: btc1.trezor.io
(would break? ), or anything.that.ends.with.trezor.io
which is guaranteed not to be scammy-url.net
so it's ok ✔️
81d0bd8
to
a40a5be
Compare
@@ -2,9 +2,14 @@ import path from 'path'; | |||
import http from 'http'; | |||
import WebSocket from 'ws'; | |||
|
|||
// Todo: Currently this needs to be done in order to interceptor in test to work. | |||
// This shall be taken care of, as we shall be intercepting the native fetch as well. | |||
// import fetch from 'node-fetch'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karliatto FYI, this is what we have been talking about
|
||
return; | ||
|
||
case 'INTERCEPTED_HEADERS': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those events does not seem to be handled anywhere, despite being (potentially) emitted.
I am not sure if this switch is supposed to be actually exhaustive, but as those are not handled anywhere, else (and also not here originally).
a40a5be
to
22d43d9
Compare
22d43d9
to
834759a
Compare
@@ -73,6 +76,9 @@ export const interceptNetSocketConnect = (context: InterceptorContext) => { | |||
details = typeof callback === 'string' ? `${callback}:${request}` : request.toString(); | |||
} | |||
|
|||
const hostname = details.split(':')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Todo: This is sub-optimal and it wont probably work in all scenarios. Any ideas?
return ''; | ||
}; | ||
|
||
const hostname = getHostname().split(':')[0] ?? ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Todo: This is sub-optimal and it wont probably work in all scenarios. Any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as we discussed the new URL(address).hostname
- I just now realised you could create a helper that would do it optionally, something like:
optionalGetUrlHostname = (address: string) => {
try {
return new URL(address).hostname;
}
catch(_err) {
return null;
}
}
then use it like hostname = optionalGetUrlHostname(address) ?? ''
file:///...
➡️ ''
✔️
invalid URLs ➡️ null
➡️ ''
✔️
…ess of the electrum
834759a
to
e66a922
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not test yet, CR'd most of code, so dropping off comments 💬
callback, | ||
validateRequest, | ||
}: OverloadHttpRequestParams) => { | ||
const hostname = typeof url === 'object' ? url.hostname ?? url.host ?? '' : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this means that for string url, hostname will always be ''
, which will always be false in isWhitelistedHost
mainThreadEmitter.emit('module/request-interceptor', { | ||
type: 'ADD_WHITELISTED_DOMAIN', | ||
domain: urlObj.hostname ?? urlObj.host, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly this effectively adds coinjoin coordinator URL to allowed domains?
if (event.type === 'CIRCUIT_MISBEHAVING') { | ||
mainThreadEmitter.emit('module/reset-tor-circuits', event); | ||
default: { | ||
const _exhaustiveCheck: never = event; // Poor-man's `switch-exhaustiveness-check` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why poor man's? This is absolutely fine 😄
Although typed record is better when mapping primitive values to cases, I would not use it to map functions. That would not read very well IMO.
return; | ||
|
||
case 'SET_WHITELISTED_DOMAINS_FOR_CUSTOM_BACKENDS': | ||
mainThreadAllowedDomain.customBackends[event.coin] = event.domains; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no reverse action when resetting a custom backend to default, so it will probably persist as enabled until you restart app or set custom backend again for the same coin.
I'm not saying it's needed, just a note. I think it's OK.
|
||
const urlObj = new URL(url); | ||
|
||
return urlObj.hostname ?? urlObj.host; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI here you can see difference between hostname and host https://developer.mozilla.org/en-US/docs/Web/API/Location
I'd only use hostname (w/o port), so the condition is broader = more restrictive
Also, both are typed as string, so I expect the ??
to be useless, maybe you meant ||
?
Resolve #7171
interceptor.test.ts
testThe whitelist needs to be probably different from the one used in render process(no, consulted with Carlos)fetch
from node.js as well and not just withnode-fetch
=> this needs to be discussed with Carlos