mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-14 06:47:28 +00:00
Block IPv4-compatible IPv6 feed URLs (#32)
Co-authored-by: Codex Microtask Operator <codex-microtask@example.com>
This commit is contained in:
parent
307095d5e9
commit
774d461db6
2 changed files with 11 additions and 0 deletions
|
|
@ -67,6 +67,16 @@ function isBlockedIp(value: string) {
|
|||
|
||||
if (kind === 6) {
|
||||
const normalized = value.toLowerCase();
|
||||
const compatibleDottedIpv4 = /^::(\d+\.\d+\.\d+\.\d+)$/.exec(normalized);
|
||||
if (compatibleDottedIpv4) {
|
||||
return isBlockedIp(compatibleDottedIpv4[1]);
|
||||
}
|
||||
const compatibleHexIpv4 = /^::([0-9a-f]{1,4}):([0-9a-f]{1,4})$/.exec(normalized);
|
||||
if (compatibleHexIpv4) {
|
||||
const high = Number.parseInt(compatibleHexIpv4[1], 16);
|
||||
const low = Number.parseInt(compatibleHexIpv4[2], 16);
|
||||
return isBlockedIp(`${high >> 8}.${high & 255}.${low >> 8}.${low & 255}`);
|
||||
}
|
||||
const mappedDottedIpv4 = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/.exec(normalized);
|
||||
if (mappedDottedIpv4) {
|
||||
return isBlockedIp(mappedDottedIpv4[1]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue