@@ -63,6 +63,31 @@ function createRequestModifier (getState, dnslinkResolver, ipfsPathValidator, ru
63
63
}
64
64
}
65
65
66
+ // Returns a canonical hostname representing the site from url
67
+ // Main reason for this is unwrapping DNSLink from local subdomain
68
+ // <fqdn>.ipns.localhost → <fqdn>
69
+ const findSiteFqdn = ( url ) => {
70
+ if ( isIPFS . ipnsSubdomain ( url ) ) {
71
+ // convert subdomain's <fqdn>.ipns.gateway.tld to <fqdn>
72
+ const fqdn = dnslinkResolver . findDNSLinkHostname ( url )
73
+ if ( fqdn ) return fqdn
74
+ }
75
+ return new URL ( url ) . hostname
76
+ }
77
+
78
+ // Finds canonical hostname of request.url and its parent page (if present)
79
+ const findSiteHostnames = ( request ) => {
80
+ const { url, originUrl, initiator } = request
81
+ const fqdn = findSiteFqdn ( url )
82
+ // FF: originUrl (Referer-like Origin URL), Chrome: initiator (just Origin)
83
+ const parentUrl = originUrl || initiator
84
+ // String value 'null' is explicitly set by Chromium in some contexts
85
+ const parentFqdn = parentUrl && parentUrl !== 'null' && url !== parentUrl
86
+ ? findSiteFqdn ( parentUrl )
87
+ : null
88
+ return { fqdn, parentFqdn }
89
+ }
90
+
66
91
const preNormalizationSkip = ( state , request ) => {
67
92
// skip requests to the custom gateway or API (otherwise we have too much recursion)
68
93
if ( sameGateway ( request . url , state . gwURL ) || sameGateway ( request . url , state . apiURL ) ) {
@@ -76,15 +101,19 @@ function createRequestModifier (getState, dnslinkResolver, ipfsPathValidator, ru
76
101
if ( request . url . startsWith ( 'http://127.0.0.1' ) || request . url . startsWith ( 'http://localhost' ) || request . url . startsWith ( 'http://[::1]' ) ) {
77
102
ignore ( request . requestId )
78
103
}
104
+
79
105
// skip if a per-site opt-out exists
80
- const parentUrl = request . originUrl || request . initiator // FF: originUrl (Referer-like Origin URL), Chrome: initiator (just Origin)
81
- const fqdn = new URL ( request . url ) . hostname
82
- const parentFqdn = parentUrl && parentUrl !== 'null' && request . url !== parentUrl ? new URL ( parentUrl ) . hostname : null
83
- if ( state . noIntegrationsHostnames . some ( optout =>
84
- fqdn !== 'gateway.ipfs.io' && ( fqdn . endsWith ( optout ) || ( parentFqdn && parentFqdn . endsWith ( optout ) )
85
- ) ) ) {
106
+ const { fqdn, parentFqdn } = findSiteHostnames ( request )
107
+ const triggerOptOut = ( optout ) => {
108
+ // Disable optout on canonical public gateway
109
+ if ( fqdn === 'gateway.ipfs.io' ) return false
110
+ if ( fqdn . endsWith ( optout ) || ( parentFqdn && parentFqdn . endsWith ( optout ) ) ) return true
111
+ return false
112
+ }
113
+ if ( state . noIntegrationsHostnames . some ( triggerOptOut ) ) {
86
114
ignore ( request . requestId )
87
115
}
116
+
88
117
// additional checks limited to requests for root documents
89
118
if ( request . type === 'main_frame' ) {
90
119
// lazily trigger DNSLink lookup (will do anything only if status for root domain is not in cache)
0 commit comments