Skip to content

Lightpanda: the headless browser designed for AI and automation

iframe: load about:blank on un-parsable URL

Karl Seguin6b6b17240e20
diff --git a/src/browser/Frame.zig b/src/browser/Frame.zig
index 0a78cd0e2..311ef8401 100644
--- a/src/browser/Frame.zig
+++ b/src/browser/Frame.zig
@@ -1751,6 +1751,11 @@ pub fn iframeAddedCallback(self: *Frame, iframe: *IFrame) !void {
src = "about:blank";
}
+ if (URL.isCompleteHTTPUrl(src) and !URL.canParse(src, null)) {
+ // per spec, if we can't parse the URL, we should load about:blank
+ src = "about:blank";
+ }
+
if (iframe._window != null) {
// This frame is being re-navigated. We need to do this through a
// scheduleNavigation phase. We can't navigate immediately here, for
diff --git a/src/browser/URL.zig b/src/browser/URL.zig
index fc78e5a3e..e96b128d6 100644
--- a/src/browser/URL.zig
+++ b/src/browser/URL.zig
@@ -62,6 +62,13 @@ pub fn resolveNavigation(allocator: Allocator, url: []const u8, options: Resolve
};
}
+pub fn canParse(url: []const u8, maybe_base: ?[]const u8) bool {
+ if (maybe_base) |base| {
+ return U.url_can_parse_with_base(base.ptr, base.len, url.ptr, url.len);
+ }
+ return U.url_can_parse(url.ptr, url.len);
+}
+
const EncodeSet = enum { path, query, query_legacy, userinfo, fragment, component };
pub fn percentEncodeSegment(allocator: Allocator, segment: []const u8, comptime encode_set: EncodeSet) ![]const u8 {
diff --git a/src/browser/tests/frames/unparseable_src.html b/src/browser/tests/frames/unparseable_src.html
new file mode 100644
index 000000000..e2c592e34
--- /dev/null
+++ b/src/browser/tests/frames/unparseable_src.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<script src="../testing.js"></script>
+
+<script id="unparseable_src" type=module>
+ // An absolute-but-unparseable src (the bare "https://" bot-detection
+ // scripts probe with) loads about:blank instead of failing the frame.
+ {
+ const state = await testing.async();
+ const ifr = document.createElement('iframe');
+ ifr.src = 'https://';
+ document.documentElement.appendChild(ifr);
+ testing.expectEqual('about:blank', ifr.contentWindow.location.href);
+
+ // re-navigating an existing frame takes the scheduled path
+ ifr.onload = () => state.resolve();
+ ifr.src = 'https://';
+ await state.done(() => {
+ testing.expectEqual('about:blank', ifr.contentWindow.location.href);
+ });
+ }
+</script>
diff --git a/src/browser/webapi/URL.zig b/src/browser/webapi/URL.zig
index b130275e5..e65987a66 100644
--- a/src/browser/webapi/URL.zig
+++ b/src/browser/webapi/URL.zig
@@ -309,12 +309,7 @@ pub fn toString(self: *const URL, exec: *const Execution) ![]const u8 {
return out[0..len];
}
-pub fn canParse(url: []const u8, maybe_base: ?[]const u8) bool {
- if (maybe_base) |base| {
- return U.url_can_parse_with_base(base.ptr, base.len, url.ptr, url.len);
- }
- return U.url_can_parse(url.ptr, url.len);
-}
+pub const canParse = @import("../URL.zig").canParse;
pub fn createObjectURL(blob: *Blob, exec: *const Execution) ![]const u8 {
var uuid_buf: [36]u8 = undefined;