fix: stop favicon requests for private link hosts on web and mobile #5838
Mergedfe-franco(GitHub profile, opens in a new tab)merged 5 commits into
main fromrefs/pull/5838/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- packages/shared/src/privateHost.ts line 29OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +9,21 @@9+ if (octets.some((octet) => Number.isNaN(octet) || octet > 255)) {10+ return false;11+ }12+ const [first = Number.NaN, second = Number.NaN] = octets;13+ if (first === 10 || first === 127) {14+ return true;15+ }16+ if (first === 192 && second === 168) {17+ return true;18+ }19+ if (first === 172 && second >= 16 && second <= 31) {20+ return true;21+ }22+ if (first === 169 && second === 254) {23+ return true;24+ }25+ // Tailscale hands out 100.64.0.0/10.26+ return first === 100 && second >= 64 && second <= 127;27+}28+29+function isPrivateIpv6(host: string): boolean {
- packages/shared/src/privateHost.ts line 53OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +33,21 @@33+ }34+ // fc00::/7 covers unique local addresses. fe80::/10 covers link local.35+ return /^f[cd][0-9a-f]{0,2}:/.test(address) || /^fe[89ab][0-9a-f]?:/.test(address);36+}37+38+/**39+ * True when a link host belongs to a private network.40+ *41+ * A favicon service cannot resolve such a host, so a request for it always42+ * fails. The request also tells that service the private host name.43+ */44+export function isPrivateLinkHost(host: string): boolean {45+ const normalized = host.trim().toLowerCase();46+ if (normalized.length === 0) {47+ return true;48+ }49+ if (normalized === "localhost") {50+ return true;51+ }52+ if (PRIVATE_HOST_SUFFIXES.some((suffix) => normalized.endsWith(suffix))) {53+ return true;
fe-franco(GitHub profile, opens in a new tab) changed the title
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- packages/shared/src/privateHost.ts line 70OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +50,21 @@50+ }51+ const octets = parts.map((part) => (/^\d{1,3}$/.test(part) ? Number(part) : Number.NaN));52+ if (octets.some((octet) => Number.isNaN(octet) || octet > 255)) {53+ return false;54+ }55+ const [first = Number.NaN, second = Number.NaN] = octets;56+ if (first === 10 || first === 127) {57+ return true;58+ }59+ if (first === 192 && second === 168) {60+ return true;61+ }62+ if (first === 172 && second >= 16 && second <= 31) {63+ return true;64+ }65+ if (first === 169 && second === 254) {66+ return true;67+ }68+ // Tailscale hands out 100.64.0.0/10.69+ return first === 100 && second >= 64 && second <= 127;70+}
- packages/shared/src/privateHost.ts line 12OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,12 @@1+/**2+ * Private host detection, for code that sends a host name to a third party.3+ *4+ * A public favicon service cannot resolve a private host, so a request for one5+ * always fails. The request also tells that service the private host name.6+ *7+ * This module holds no runtime dependency, so web, mobile and desktop can all8+ * import it.9+ */10+11+// RFC 6761 reserves every name under .localhost for the loopback interface.12+const PRIVATE_HOST_SUFFIXES = [".localhost", ".local", ".internal", ".home.arpa", ".ts.net"];
juliusmarminge approved these changes
juliusmarminge merged thisb6f7268
juliusmarminge closed this
Sign in to join this conversation.



Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
df6abf16-6195-47ad-9c1a-4c272c06c5d7You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share