Skip to content
Merged
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
28 changes: 17 additions & 11 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,24 @@ export function is_ip_internal(ip: string): boolean {
import { promises as dns } from "dns";

async function resolve_all_records(host: string) {
const A = await dns.resolve4(host).catch(() => []);
const AAAA = await dns.resolve6(host).catch(() => []);
const CNAME = await dns.resolveCname(host).catch(() => []);

return {
A,
AAAA,
CNAME
};
}
const [A, AAAA, CNAME] = await Promise.all([
dns.resolve4(host).catch(() => [] as string[]),
dns.resolve6(host).catch(() => [] as string[]),
dns.resolveCname(host).catch(() => [] as string[])
]);

if (A.length === 0 && AAAA.length === 0) {
try {
const lookups = await dns.lookup(host, { all: true });
for (const entry of lookups) {
if (entry.family === 4) A.push(entry.address);
if (entry.family === 6) AAAA.push(entry.address);
}
} catch {}
}

return { A, AAAA, CNAME };
}
Comment on lines +273 to +290

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. Dist build not updated 🐞 Bug ≑ Correctness

The PR updates resolve_all_records() in src/helpers.ts, but the runtime entrypoint is
dist/utils.js which uses dist/helpers.js; since dist/helpers.js still contains the old
resolver implementation, the shipped behavior will not include the new dns.lookup fallback.
Agent Prompt
### Issue description
The package runtime entrypoint is `dist/utils.js` (CommonJS), which pulls in `dist/helpers.js`. This PR changes DNS behavior only in `src/helpers.ts`, leaving the compiled `dist/` artifacts stale. As a result, consumers will not receive the new `dns.lookup` fallback.

### Issue Context
- `package.json` declares `main: dist/utils.js` and exports `./dist/utils.js`.
- `dist/helpers.js` still contains the pre-change `resolve_all_records()` implementation.
- `dist/` is not ignored, and there is no `prepublishOnly`/`prepare` script shown that would automatically rebuild `dist/` on publish.

### Fix Focus Areas
- src/helpers.ts[270-290]
- dist/helpers.js[253-263]
- package.json[20-36]
- .gitignore[1-2]

### Suggested fix
1. Run `npm run build` (tsc) to regenerate `dist/helpers.js`, `dist/utils.js`, and the corresponding `.d.ts` outputs.
2. Commit the updated `dist/` artifacts.
3. (Optional but recommended) Add a `prepublishOnly` (or `prepare`) script to ensure `dist/` is always rebuilt before publishing.

β“˜ Copy this prompt and use it to remediate the issue with your preferred AI generation tools




Expand Down Expand Up @@ -524,4 +531,3 @@ export async function is_url_safe(url: string): Promise<boolean> {
/// FIXME(): The debug version do not match is_url_safe, We'wll fix it later but for now keep it as is.
export async function is_url_safe_debug(url: string): Promise<boolean> { try { console.log("STEP 1 input:", url); let u = normalize_unicode(url); console.log("STEP 2 unicode:", u); u = replace_backslash_with_slash_in_string(u); console.log("STEP 3 slashes:", u); u = replace_two_slashes_url_to_normal_url(u); console.log("STEP 4 normalize slashes:", u); u = remove_at_symbol_in_string(u); console.log("STEP 5 remove @:", u); const schema = normalize_schema(u); if (!is_proto_safe(schema)) return false; console.log("STEP 6 schema:", schema); if (!is_proto_safe(u)) { console.log("STEP 7 proto unsafe"); return false; } console.log("STEP 7 proto safe"); const parsed = new URL(u); const hostname = parsed.hostname.replace(/^\[|\]$/g, ""); console.log("STEP 8 hostname:", hostname); if (/^\d{1,3}(\.\d{1,3}){3}$/.test(hostname)) { try { normalize_ipv4(hostname); } catch { console.log("STEP 9 ipv4 invalid"); return false; } } if (is_ipv6(hostname)) { if (is_ip_internal(hostname)) { console.log("STEP 10 ipv6 internal"); return false; } } const isInternal = await is_hostname_resolve_to_internal_ip(hostname); console.log("STEP 11 internal?", isInternal); if (isInternal) { return false; } const redirectSafe = await is_redirect_safe(u); console.log("STEP 12 redirect safe?", redirectSafe); if (!redirectSafe) { return false; } console.log("STEP 13 final: true"); return true; } catch (e) { console.log("ERROR:", e); return false; } }


Loading