Skip to content
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

feat: dns interceptor #5

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

feat: dns interceptor #5

wants to merge 3 commits into from

Conversation

ronag
Copy link
Member

@ronag ronag commented Oct 16, 2024

No description provided.

@ronag ronag requested a review from deadbeef84 October 16, 2024 11:54
@ronag ronag force-pushed the dns-interceptor branch 5 times, most recently from 9d60ded to 8d01c27 Compare October 16, 2024 11:58
// TODO (fix): What about old "blacklisted" records?
// TODO (fix): What about ipv6?

records = await resolve4(hostname, { ttl: true })
Copy link

@deadbeef84 deadbeef84 Oct 16, 2024

Choose a reason for hiding this comment

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

if there's no entry in the dnsCache, and multiple requests are made, it will create many concurrent records - possibly an issue?

also perhaps use stale-while-revalidate?

Copy link
Member Author

Choose a reason for hiding this comment

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

can avsolulety be more optimized. I'll have a look

Comment on lines +107 to +111
const record = records.find((record) => record.expires > now)

if (!record) {
return dispatch(opts, handler)
}

Choose a reason for hiding this comment

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

not sure I follow this, it was already checked at top?

Copy link
Member Author

Choose a reason for hiding this comment

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

checked where?


const { protocol, port, hostname, host } = new URL(opts.origin)

if (net.isIP(hostname) || opts.headers?.host || !port || !protocol) {

Choose a reason for hiding this comment

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

why skip when headers.host or !port?

Copy link
Member Author

Choose a reason for hiding this comment

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

We should always have port and protocol so I guess I should change that to an asser ot default to http:80.

If a host header is set I'm not sure what kind of weird issues it can cause.

{
...opts,
origin: `${protocol}//${record.address}:${port}`,
headers: { ...opts.headers, host },

Choose a reason for hiding this comment

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

why set host header?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because otherwise the host header will have the ip instead of the dns name which will cause issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants