Skip to content

Update WPT - #4358

Merged
Uzlopak merged 1 commit into
mainfrom
wpt-update
Aug 15, 2025
Merged

Uzlopak merged 1 commit into
mainfrom
wpt-update

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Automated update of the WPT

@github-actions
github-actions Bot force-pushed the wpt-update branch 6 times, most recently from 3bc0446 to 60712b3 Compare July 31, 2025 00:21
@github-actions
github-actions Bot force-pushed the wpt-update branch 3 times, most recently from 193af49 to 5627bb3 Compare August 5, 2025 00:22
@github-actions
github-actions Bot force-pushed the wpt-update branch 5 times, most recently from 490deb5 to 24cdbde Compare August 14, 2025 00:20
await test_driver.set_permission({ name: 'local-network-access' }, permission_value);

const child = document.createElement('iframe');
child.src = new URL(window.location).searchParams.get('url');

Check warning

Code scanning / CodeQL

Client-side URL redirect

Untrusted URL redirection depends on a [user-provided value](1).

Copilot Autofix

AI over 1 year ago

To fix the problem, we should validate the value of the url parameter before using it as the src of the iframe. The best way is to maintain a whitelist of allowed URLs or restrict the URLs to same-origin or a set of trusted origins. For demonstration, we can restrict the iframe source to only allow URLs that are same-origin with the current page, or match a list of allowed paths. This can be done by parsing the URL and checking its origin or path before assigning it to the iframe. The changes should be made in the script block, specifically at line 32 where the iframe's src is set.

Suggested changeset 1
test/fixtures/wpt/fetch/local-network-access/resources/iframer.html

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/fixtures/wpt/fetch/local-network-access/resources/iframer.html b/test/fixtures/wpt/fetch/local-network-access/resources/iframer.html
--- a/test/fixtures/wpt/fetch/local-network-access/resources/iframer.html
+++ b/test/fixtures/wpt/fetch/local-network-access/resources/iframer.html
@@ -29,7 +29,22 @@
     await test_driver.set_permission({ name: 'local-network-access' }, permission_value);
 
     const child = document.createElement('iframe');
-    child.src = new URL(window.location).searchParams.get('url');
+    const urlParam = new URL(window.location).searchParams.get('url');
+    let safeUrl = '';
+    if (urlParam) {
+        try {
+            const candidateUrl = new URL(urlParam, window.location.origin);
+            // Only allow same-origin URLs
+            if (candidateUrl.origin === window.location.origin) {
+                safeUrl = candidateUrl.href;
+            }
+        } catch (e) {
+            // Invalid URL, do not set src
+        }
+    }
+    if (safeUrl) {
+        child.src = safeUrl;
+    }
     document.body.appendChild(child);
 });
 </script>
\ No newline at end of file
EOF
@@ -29,7 +29,22 @@
await test_driver.set_permission({ name: 'local-network-access' }, permission_value);

const child = document.createElement('iframe');
child.src = new URL(window.location).searchParams.get('url');
const urlParam = new URL(window.location).searchParams.get('url');
let safeUrl = '';
if (urlParam) {
try {
const candidateUrl = new URL(urlParam, window.location.origin);
// Only allow same-origin URLs
if (candidateUrl.origin === window.location.origin) {
safeUrl = candidateUrl.href;
}
} catch (e) {
// Invalid URL, do not set src
}
}
if (safeUrl) {
child.src = safeUrl;
}
document.body.appendChild(child);
});
</script>
Copilot is powered by AI and may make mistakes. Always verify output.
await test_driver.set_permission({ name: 'local-network-access' }, permission_value);

const child = document.createElement('iframe');
child.src = new URL(window.location).searchParams.get('url');

Check failure

Code scanning / CodeQL

Client-side cross-site scripting

Cross-site scripting vulnerability due to [user-provided value](1).

Copilot Autofix

AI over 1 year ago

To fix this DOM-based XSS vulnerability, we must ensure that the value assigned to the iframe.src attribute is safe. The best way is to validate that the url parameter is a well-formed, safe URL, and only allow certain schemes (e.g., http:, https:) or restrict it to same-origin URLs. We should reject or ignore any value that does not meet these criteria. This can be done by parsing the URL, checking its protocol, and possibly its origin. If the value is not valid or safe, we should avoid setting the src or set it to a safe default.

The changes should be made in the region around line 32 in test/fixtures/wpt/fetch/local-network-access/resources/iframer.html. No new libraries are needed; we can use the built-in URL API for validation.


Suggested changeset 1
test/fixtures/wpt/fetch/local-network-access/resources/iframer.html

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/fixtures/wpt/fetch/local-network-access/resources/iframer.html b/test/fixtures/wpt/fetch/local-network-access/resources/iframer.html
--- a/test/fixtures/wpt/fetch/local-network-access/resources/iframer.html
+++ b/test/fixtures/wpt/fetch/local-network-access/resources/iframer.html
@@ -29,7 +29,24 @@
     await test_driver.set_permission({ name: 'local-network-access' }, permission_value);
 
     const child = document.createElement('iframe');
-    child.src = new URL(window.location).searchParams.get('url');
+    const urlParam = new URL(window.location).searchParams.get('url');
+    let safeUrl = '';
+    try {
+        if (urlParam) {
+            const parsedUrl = new URL(urlParam, window.location.origin);
+            if (parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:') {
+                safeUrl = parsedUrl.href;
+            }
+        }
+    } catch (e) {
+        // Invalid URL, leave safeUrl as empty string
+    }
+    if (safeUrl) {
+        child.src = safeUrl;
+    } else {
+        // Optionally, set a safe default or do not set src at all
+        child.src = 'about:blank';
+    }
     document.body.appendChild(child);
 });
 </script>
\ No newline at end of file
EOF
@@ -29,7 +29,24 @@
await test_driver.set_permission({ name: 'local-network-access' }, permission_value);

const child = document.createElement('iframe');
child.src = new URL(window.location).searchParams.get('url');
const urlParam = new URL(window.location).searchParams.get('url');
let safeUrl = '';
try {
if (urlParam) {
const parsedUrl = new URL(urlParam, window.location.origin);
if (parsedUrl.protocol === 'http:' || parsedUrl.protocol === 'https:') {
safeUrl = parsedUrl.href;
}
}
} catch (e) {
// Invalid URL, leave safeUrl as empty string
}
if (safeUrl) {
child.src = safeUrl;
} else {
// Optionally, set a safe default or do not set src at all
child.src = 'about:blank';
}
document.body.appendChild(child);
});
</script>
Copilot is powered by AI and may make mistakes. Always verify output.
<script>
const window_url = new URL(window.location.href);
targetUrl = window_url.searchParams.get('url');
window.location.href = targetUrl;

Check warning

Code scanning / CodeQL

Client-side URL redirect

Untrusted URL redirection depends on a [user-provided value](1).

Copilot Autofix

AI over 1 year ago

To fix the problem, we should avoid redirecting to arbitrary URLs provided by the user. Instead, we should maintain a whitelist of allowed URLs or restrict redirects to same-origin URLs only. The best way to do this in the context of this snippet is to check that the target URL is either a relative path or has the same origin as the current page. If the check fails, we should avoid redirecting or redirect to a safe default location. The changes should be made in the <script> block, specifically lines 7-8, and may require a helper function to validate the URL.

Suggested changeset 1
test/fixtures/wpt/fetch/local-network-access/resources/navigate.html

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/fixtures/wpt/fetch/local-network-access/resources/navigate.html b/test/fixtures/wpt/fetch/local-network-access/resources/navigate.html
--- a/test/fixtures/wpt/fetch/local-network-access/resources/navigate.html
+++ b/test/fixtures/wpt/fetch/local-network-access/resources/navigate.html
@@ -4,6 +4,20 @@
 <body></body>
 <script>
   const window_url = new URL(window.location.href);
-  targetUrl = window_url.searchParams.get('url');
-  window.location.href = targetUrl;
+  const targetUrl = window_url.searchParams.get('url');
+  // Only allow same-origin or relative URLs for redirect
+  if (targetUrl) {
+    try {
+      const parsedUrl = new URL(targetUrl, window.location.origin);
+      if (parsedUrl.origin === window.location.origin) {
+        window.location.href = parsedUrl.href;
+      } else {
+        // Unsafe redirect, go to homepage or show error
+        window.location.href = '/';
+      }
+    } catch (e) {
+      // Malformed URL, go to homepage or show error
+      window.location.href = '/';
+    }
+  }
 </script>
\ No newline at end of file
EOF
@@ -4,6 +4,20 @@
<body></body>
<script>
const window_url = new URL(window.location.href);
targetUrl = window_url.searchParams.get('url');
window.location.href = targetUrl;
const targetUrl = window_url.searchParams.get('url');
// Only allow same-origin or relative URLs for redirect
if (targetUrl) {
try {
const parsedUrl = new URL(targetUrl, window.location.origin);
if (parsedUrl.origin === window.location.origin) {
window.location.href = parsedUrl.href;
} else {
// Unsafe redirect, go to homepage or show error
window.location.href = '/';
}
} catch (e) {
// Malformed URL, go to homepage or show error
window.location.href = '/';
}
}
</script>
Copilot is powered by AI and may make mistakes. Always verify output.
<script>
const window_url = new URL(window.location.href);
targetUrl = window_url.searchParams.get('url');
window.location.href = targetUrl;

Check failure

Code scanning / CodeQL

Client-side cross-site scripting

Cross-site scripting vulnerability due to [user-provided value](1).

Copilot Autofix

AI over 1 year ago

To fix this vulnerability, the code should validate and sanitize the url parameter before using it as a navigation target. The safest approach is to only allow navigation to trusted URLs. A common pattern is to only allow relative URLs (i.e., URLs that do not specify a protocol or domain), or to check that the URL is on the same origin. Alternatively, a whitelist of allowed domains can be used. In this case, we will restrict navigation to same-origin URLs by checking that the resolved target URL has the same origin as the current page. If the check fails, we can either do nothing or navigate to a safe default.

Required changes:

  • Parse the targetUrl as a URL, resolving it relative to the current location.
  • Check that the resulting URL's origin matches window.location.origin.
  • Only assign to window.location.href if the check passes.
  • Optionally, handle the case where the check fails (e.g., show an error or navigate to a safe default).

No new imports are needed, as the standard URL API is available in browsers.


Suggested changeset 1
test/fixtures/wpt/fetch/local-network-access/resources/navigate.html

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/test/fixtures/wpt/fetch/local-network-access/resources/navigate.html b/test/fixtures/wpt/fetch/local-network-access/resources/navigate.html
--- a/test/fixtures/wpt/fetch/local-network-access/resources/navigate.html
+++ b/test/fixtures/wpt/fetch/local-network-access/resources/navigate.html
@@ -4,6 +4,19 @@
 <body></body>
 <script>
   const window_url = new URL(window.location.href);
-  targetUrl = window_url.searchParams.get('url');
-  window.location.href = targetUrl;
+  const targetUrl = window_url.searchParams.get('url');
+  if (targetUrl) {
+    try {
+      const resolvedUrl = new URL(targetUrl, window.location.href);
+      if (resolvedUrl.origin === window.location.origin) {
+        window.location.href = resolvedUrl.href;
+      } else {
+        // Optionally, handle invalid navigation attempt
+        // alert('Navigation to external origins is not allowed.');
+      }
+    } catch (e) {
+      // Optionally, handle invalid URL
+      // alert('Invalid URL.');
+    }
+  }
 </script>
\ No newline at end of file
EOF
@@ -4,6 +4,19 @@
<body></body>
<script>
const window_url = new URL(window.location.href);
targetUrl = window_url.searchParams.get('url');
window.location.href = targetUrl;
const targetUrl = window_url.searchParams.get('url');
if (targetUrl) {
try {
const resolvedUrl = new URL(targetUrl, window.location.href);
if (resolvedUrl.origin === window.location.origin) {
window.location.href = resolvedUrl.href;
} else {
// Optionally, handle invalid navigation attempt
// alert('Navigation to external origins is not allowed.');
}
} catch (e) {
// Optionally, handle invalid URL
// alert('Invalid URL.');
}
}
</script>
Copilot is powered by AI and may make mistakes. Always verify output.

@Uzlopak Uzlopak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@Uzlopak
Uzlopak merged commit 7db221a into main Aug 15, 2025
@Uzlopak
Uzlopak deleted the wpt-update branch August 15, 2025 15:59
@github-actions github-actions Bot mentioned this pull request Aug 17, 2025
slagiewka pushed a commit to slagiewka/undici that referenced this pull request Feb 14, 2026
Co-authored-by: Uzlopak <5059100+Uzlopak@users.noreply.github.com>
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