Commit graph

63 commits

Author SHA1 Message Date
Aliaksandr Kalenik
ff95e47802 LibWeb+LibWebView+WebContent: Send service sockets over IPC channel
Instead of passing RequestServer and ImageDecoder socket FDs as
command-line arguments to WebContent, send them over the main IPC
channel after launch. This unifies initial connection and reconnection
into a single code path.
2026-03-12 20:32:55 +01:00
Timothy Flynn
e6c008a269 LibWeb+RequestServer: Attach HTTP cookie headers from RequestServer
We currently attach HTTP cookie headers from LibWeb within Fetch. This
has the downside that the cookie IPC, and the infrastructure around it,
are all synchronous. This blocks the WebContent process entirely while
the cookie is being retrieved, for every request on a page.

We now attach cookie headers from RequestServer. The state machine in
RequestServer::Request allows us to easily do this work asynchronously.
We can also skip this work entirely when the response is served from
disk cache.

Note that we will continue to parse cookies in the WebContent process.
If something goes awry during parsing. we limit the damage to that
process, instead of the UI or RequestServer.

Also note that WebSocket requests still have cookie headers attached
attached from LibWeb. This will be handled in a future patch.

In the future, we may want to introduce a memory cache for cookies in
RequestServer to avoid IPC altogether as able.
2026-02-10 12:21:20 +01:00
Timothy Flynn
8d97389038 LibHTTP+Everywhere: Move the cookie implementation to LibHTTP
This will allow parsing cookies outside of LibWeb.

LibHTTP is basically becoming the home of HTTP WG specs.
2026-02-10 12:21:20 +01:00
Timothy Flynn
9f436356d0 LibWeb: Interpret cookie headers as UTF-8
The cookie RFC strongly suggests that cookies only contain ASCII, and
that non-ASCII values be encoded with e.g. base64. Web reality differs,
however, and browsers are expected to support UTF-8 encoded cookies.
This aligns with document.cookie.

This fixes the following WPT tests:

    /cookies/encoding/charset.html
    /cookiestore/encoding.https.any.html

No test added here because we don't have a mechanism yet to set an
HTTP cookie and inspect it via our file:// URL test infra.
2026-02-08 23:14:31 +01:00
Timothy Flynn
8156531477 LibWeb: Decode Set-Cookie response headers before parsing
It's possible for the cookie value from a Set-Cookie header to contain
invalid UTF-8. We must isomorphic decode this header.

This fixes the /cookies/domain/domain-attribute-idn-host.sub.https.html
WPT test. The test added here is a crash test rather than a text test
because we cannot access the received Set-Cookie header from JS on the
file:// test URL.
2026-02-03 07:20:41 -05:00
Timothy Flynn
5a186ebd5d LibWeb: Remove unnecessary FIXME about cookie sources
The source here is decidedly HTTP, as this is specifically setting the
cookie value from the Set-Cookie HTTP header.
2026-02-03 07:20:41 -05:00
Zaggy1024
32441d3a46 LibWeb: Make FetchController::stop_fetch() cancel the request 2026-01-29 05:22:27 -06:00
Timothy Flynn
aa1517b727 LibHTTP+LibWeb+RequestServer: Handle the Fetch API's cache mode
If the cache mode is no-store, we must not interact with the cache at
all.

If the cache mode is reload, we must not use any cached response.

If the cache-mode is only-if-cached or force-cache, we are permitted
to respond with stale cache responses.

Note that we currently cannot test only-if-cached in test-web. Setting
this mode also requires setting the cors mode to same-origin, but our
http-test-server infra requires setting the cors mode to cors.
2026-01-22 07:05:06 -05:00
Andreas Kling
7e7ef058a6 LibWeb: Move NavigatorCompatibilityMode enum to its own file
This makes it less painful to edit UserAgent.h (due to recompiles).
2026-01-17 09:30:16 +01:00
Andreas Kling
681d00c218 LibDevTools: Pass request initiator type to network panel
Propagate the request initiator type (e.g., "xmlhttprequest", "fetch",
"script", "stylesheet") from LibWeb through the IPC layer to DevTools.

This enables Firefox DevTools to correctly identify XHR/fetch requests
and display appropriate cause types in the Network panel's "Initiator"
column.
2026-01-15 20:10:19 +01:00
Andreas Kling
31ffd2e8e5 LibDevTools: Add request and response body viewing to network panel
This adds support for viewing request payloads (POST data) and response
bodies in the Firefox DevTools network panel.

Request bodies are captured when network requests start and passed
through IPC to the NetworkEventActor, which returns them via the
getRequestPostData protocol method.

Response bodies are streamed via a new IPC message as data is received,
accumulated in NetworkEventActor (with a 10MB size limit to prevent
memory issues), and returned via getResponseContent. Text content is
returned as UTF-8, while binary content (images, etc.) is base64.
2026-01-15 20:10:19 +01:00
Andreas Kling
cf010885d5 LibDevTools: Add Firefox DevTools network monitoring support
Hook ResourceLoader to emit network request lifecycle events through
IPC to the UI process, where FrameActor creates NetworkEventActor
instances that serialize requests using Firefox's Remote Debug Protocol.

The Network panel now shows requests with method, URL, status, MIME
type, size, and timing information. Several features remain stubbed
(POST data, response content, cause detection) marked with FIXMEs.
2026-01-15 20:10:19 +01:00
Jelle Raaijmakers
f2cf5df961 LibWeb: Show the network error if request failed
We were dropping the actual network error on the floor when reporting
that something had failed.
2026-01-08 06:41:30 -05:00
Timothy Flynn
d4927b94de LibWeb: Make fewer copies of GC::Root fetch callbacks 2025-12-21 09:24:51 -06:00
Timothy Flynn
674075f79e Everywhere: Remove LibCore/System.h includes from header files
This reduces the number of compilation jobs when System.h changes from
about 750 to 60. (There are still a large number of linker jobs.)
2025-12-04 15:40:46 +00:00
Timothy Flynn
9375660b64 LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP
The end goal here is for LibHTTP to be the home of our RFC 9111 (HTTP
caching) implementation. We currently have one implementation in LibWeb
for our in-memory cache and another in RequestServer for our disk cache.

The implementations both largely revolve around interacting with HTTP
headers. But in LibWeb, we are using Fetch's header infra, and in RS we
are using are home-grown header infra from LibHTTP.

So to give these a common denominator, this patch replaces the LibHTTP
implementation with Fetch's infra. Our existing LibHTTP implementation
was not particularly compliant with any spec, so this at least gives us
a standards-based common implementation.

This migration also required moving a handful of other Fetch AOs over
to LibHTTP. (It turns out these AOs were all from the Fetch/Infra/HTTP
folder, so perhaps it makes sense for LibHTTP to be the implementation
of that entire set of facilities.)
2025-11-27 14:57:29 +01:00
Timothy Flynn
0480934afb LibHTTP+LibWeb: Remove unused HTTP::HTTPResponse
The only thing in HTTPResponse being used is reason_phrase_for_code,
which is just a static helper method. Move it to its own file and remove
HTTPResponse.

This is just one less thing to have to port to an upcoming HTTP header
refactor.
2025-11-27 14:57:29 +01:00
Aliaksandr Kalenik
69cede4a0f AK+LibWeb: Make StringBase::bytes() lvalue-only
Disallow calling `StringBase::bytes()` on temporaries to avoid returning
`ReadonlyBytes` that outlive the underlying string.

With this change, we catch a real UAF:
`load_result.data = maybe_response.release_value().bytes();`
All other updated call sites were already safe, they just needed to use
an intermediate named variable to satisfy the new lvalue-only
requirement.
2025-11-25 13:02:20 -05:00
Aliaksandr Kalenik
16b0f1e6c2 LibWeb: Delete unused ResourceLoader::load()
...and rename `load_unbuffered()` to `load()`.
2025-11-20 06:29:13 -05:00
Aliaksandr Kalenik
3058274386 LibWeb: Use unbuffered network requests for all Fetch requests
Previously, unbuffered requests were only available as a special mode
for EventSource. With this change, they are enabled by default, which
means chunks can be read from the stream as soon as they arrive.

This unlocks some interesting possibilities, such as starting to parse
HTML documents before the entire response has been received (that, in
turn, allows us to initiate subresource fetches earlier or begin
executing scripts sooner), or start rendering videos before they are
fully downloaded.

Co-authored-by: Timothy Flynn <trflynn89@pm.me>
2025-11-20 06:29:13 -05:00
Aliaksandr Kalenik
cce5197f90 LibWeb: Implement :resource support for load_unbuffered()
Preparation work before enabling unbuffered fetching by default.
2025-11-20 06:29:13 -05:00
Aliaksandr Kalenik
1f4b53d9fc LibWeb: Implement :about protocol support for load_unbuffered()
Preparation work before enabling unbuffered fetching by default.
2025-11-20 06:29:13 -05:00
Aliaksandr Kalenik
2fd7b70784 LibWeb: Implement file: protocol support for load_unbuffered()
Preparation work before enabling unbuffered fetching by default.
2025-11-20 06:29:13 -05:00
Timothy Flynn
ac246caa0c LibWeb: Remove now-unused Resource and ResourceClient
And deal with the fallout of transitive includes.
2025-11-05 18:27:36 +01:00
Julian Dominguez-Schatz
4e3387778e LibWeb: Respect IncludeCredentials for Set-Cookie during fetch
Per https://fetch.spec.whatwg.org/#http-network-fetch, Set-Cookie should
only store a cookie if IncludeCredentials::Yes is set. Fixes 1 web
platform test.
2025-09-24 10:12:56 +01:00
Timothy Flynn
b1b218596f LibWeb+WebContent: Add IPC to re-establish RequestServer connections 2025-08-10 11:02:50 +02:00
Timothy Flynn
3171d57639 LibWeb: Restore flags to prevent formatting timestamps as local time
The flag to stringify these timestamps as UTC was errantly dropped in
6fb2be96bf. This was causing test-web to
fail in time zones other than GMT+0.
2025-06-25 23:41:04 +02:00
Tomasz Strejczek
6fb2be96bf Everywhere: Replace DateTime::to_string() with UnixDateTime::to_string()
Replace LibCore::DateTime::to_string() with
AK::UnixDateTime::to_string().
Remove unncessary #include <LibCore/DateTime.h>.
2025-06-19 18:42:45 -06:00
Callum Law
6c3ceb9284 LibWeb: Don't crash when handling invalid HTTP status codes
Example crash: https://wpt.live/fetch/h1-parsing/status-code.window.html

There is still work to make the above tests pass.
2025-05-27 12:58:08 -06:00
Timothy Flynn
6539c72e7e LibWeb: Allow CORS requests from opaque origins to resource:// URLs
JavaScript module requests (in a non-worker context) always have CORS
enabled. However, CORS requests are only allowed for same-origin or
HTTP/S requests. This patch extends this to allow resource:// requests
from opaque origins (e.g. about: URLs).

We must also set the Access-Control-Allow-Origin header to "null" to
ensure that the response is accepted by the CORS checks. This does not
affect requesting resource:// URLs from resource:// URLs as those are
same-origin and skip CORS checks.

This ultimately enables requesting resource:// JS modules from the
about:settings page.
2025-04-23 19:58:58 -04:00
Shannon Booth
733dfdaa05 LibWeb: Avoid URL validity check for 'Resource'
Which was previously signally an invalid Resource by a default
constructed invalid URL. Instead, switch this over to an Optional
URL.
2025-04-19 07:18:43 -04:00
stasoid
32ddeb82d6 LibURL+LibWeb: Remove leading slash when converting url to path
...on Windows
2025-04-10 19:04:21 -06:00
Timothy Flynn
0de017df9b LibRequests: Move NetworkError stringification to LibRequests
Let's also rename the file to NetworkError.h while we're here. No need
to have "Enum" in the name.
2025-04-02 08:52:45 -04:00
Gingeh
5838c73a72 LibWeb: Restrict weird about:foo URIs
This commit:
- Prevents path traversal via the about: scheme
- Prevents loading about:inspector
- Requires about: URIs to be opaque paths
- Prevents crashes with invalid percent encoded paths
2025-03-12 10:41:06 +00:00
Luke Wilde
209b10e53e RequestServer: Retrieve timing info from curl and pipe it to LibWeb
This timing info will be used to create a PerformanceResourceTiming
entry.
2025-03-06 09:00:53 -07:00
Shannon Booth
097f7fe169 LibWeb/Loader: Explicitly parse URL generating directory response
Removing one more caller of the implicit URL constructors.
2025-03-04 16:24:19 -05:00
Andrew Kaster
47716a4e11 LibWeb: Explicitly capture resource in closures in load_resource
A hygine patch to not use a generic = capture, and remove some
unnecessary const-casts
2025-02-18 11:26:34 -07:00
Andrew Kaster
8760825bb4 LibWeb: Don't store Page on ResourceLoader
We only need a Page for file:// urls. At some point we probably
needed it for other kinds of requests, but the current functionality
doesn't need to store the Page pointer on the ResourceLoader.
2025-02-18 11:26:34 -07:00
Shannon Booth
f87041bf3a LibGC+Everywhere: Factor out a LibGC from LibJS
Resulting in a massive rename across almost everywhere! Alongside the
namespace change, we now have the following names:

 * JS::NonnullGCPtr -> GC::Ref
 * JS::GCPtr -> GC::Ptr
 * JS::HeapFunction -> GC::Function
 * JS::CellImpl -> GC::Cell
 * JS::Handle -> GC::Root
2024-11-15 14:49:20 +01:00
Andreas Kling
b3b97d2049 LibWeb: Unregister network requests *after* invoking callbacks
This ensures that the network request actually gets unreffed and deleted
at the right time.
2024-11-11 21:40:56 +01:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
Andreas Kling
a6d52e0c97 LibWeb: Add a basic content filter (ad blocking!) :^)
This patch adds a global (per-process) filter list to LibWeb that is
used to filter all outgoing resource load requests.

Basically we check the URL against a list of filter patterns and if
it's a match for any one of them, we immediately fail the load.

The filter list is a simple text file:

    ~/.config/BrowserContentFilters.txt

It's one filter per line and they are simple glob filters for now,
with implicit asterisks (*) at the start and end of the line.
2021-01-05 21:20:15 +01:00
Andreas Kling
5e157eaf37 LibWeb: Convert a bunch of String::format() => String::formatted() 2021-01-03 14:35:09 +01:00
Tom
a4b3eb6b2d LibWeb: Clear circular download reference when download finished 2020-12-31 22:15:00 +01:00
AnotherTest
83fed3fd5d LibWeb: Don't hold on to the Download instance after it's finished
Fixes* 4668
2020-12-31 16:57:09 +01:00
AnotherTest
4a2da10e38 ProtocolServer: Stream the downloaded data if possible
This patchset makes ProtocolServer stream the downloads to its client
(LibProtocol), and as such changes the download API; a possible
download lifecycle could be as such:
notation = client->server:'>', server->client:'<', pipe activity:'*'
```
> StartDownload(GET, url, headers, {})
< Response(0, fd 8)
* {data, 1024b}
< HeadersBecameAvailable(0, response_headers, 200)
< DownloadProgress(0, 4K, 1024)
* {data, 1024b}
* {data, 1024b}
< DownloadProgress(0, 4K, 2048)
* {data, 1024b}
< DownloadProgress(0, 4K, 1024)
< DownloadFinished(0, true, 4K)
```

Since managing the received file descriptor is a pain, LibProtocol
implements `Download::stream_into(OutputStream)`, which can be used to
stream the download into any given output stream (be it a file, or
memory, or writing stuff with a delay, etc.).
Also, as some of the users of this API require all the downloaded data
upfront, LibProtocol also implements `set_should_buffer_all_input()`,
which causes the download instance to buffer all the data until the
download is complete, and to call the `on_buffered_download_finish`
hook.
2020-12-30 13:31:55 +01:00
Andreas Kling
497f1fd472 LibWeb: Don't use ByteBuffer::wrap() when loading about: URLs
Let's just copy an empty string here to make ourselves a ByteBuffer.
2020-12-19 18:29:13 +01:00
Andreas Kling
685d5f4e25 LibProtocol: Remove use of ByteBuffer::wrap() in protocol API 2020-12-19 13:09:02 +01:00
Luke
62a74bf282 LibWeb: Advertise to servers that we support gzip encoding
We've had gzip support for a while now, but it never really got
used because we never advertised it.
2020-11-11 12:15:18 +01:00