Commit Graph
41 Commits
Author SHA1 Message Date
Karl Seguin 6a83881634 chore: add lp.IS_DEBUG and lp.IS_TEST
Change all users to builtin.mode and built.is_test
2026-08-01 09:15:18 +08:00
Adrià Arrufat cbce632401 Replace @cImport with build-system translateC
Zig 0.17 removes @cImport in favor of translate-c steps in the build
system. Each library's link function now creates an addTranslateC step
exposed as a module import: curl and isocline translate their headers
straight from the dependency tree, while sqlite3 uses the artifact's
emitted include tree since the amalgamation lives in a sub-dependency.

Terminal.zig and prompt_assist.zig previously instantiated two
independent @cImport namespaces for isocline; they now share one
translated module, so its types are identical across both files.
2026-07-27 12:07:28 +02:00
Karl Seguin 5acfd38250 Improve CDP response event data
Give accurate connectionId, connectionReused, initialPriority and securityState
values.

Always set `referrerPolicy` to `unsafe-url` as the most honest answer (we should
implement proper referrer policy!).

For workers, track the underlying frame_id so that it can be used for the
`documentURL` field.
2026-07-25 11:36:13 +08:00
Halil Durak a4ba95b3ad changes for Zig 0.16 (again) 2026-07-22 18:29:33 +03:00
Halil Durak b791512b37 libcrypto: remove dead bindings 2026-07-22 18:29:32 +03:00
Halil Durak 1c97bc42a4 crypto: more bindings
* bind `X509_STORE_get0_objects`,
* bind `sk_num`,
* bind `sk_X509_OBJECT_num`,
* add `getCertCount` helper.
2026-07-22 18:29:29 +03:00
Karl Seguin df7bde233d Fix linux build
Try to fix CI (this is what claude came up with, I have no idea why CI is
failing).
2026-07-22 13:26:06 +08:00
Karl Seguin 8e42d63c1c zig: Zig 0.16
Built against https://github.com/lightpanda-io/zig-v8-fork/tree/zig-0.16 but
it doesn't require a new v8 build.

Built against https://github.com/lightpanda-io/boringssl-zig/tree/zig-0.16
since the current fork we point to isn't updated.

A global std.Io instance, lp.io. Way easier this way and requires 0 changes to
our libcurl integration / event loop.

Network code uses a new layer that does what Zig 0.15's posix package used to
do. Again, quicker migration that way. But, as long as we have the global IO,
and given the half-baked nature of networking in std.Io 0.16, this just makes
sense. Things can be migrated as needed.

The std.time.* -> std.Io.Timestamp/Clock/Duration resulted in _a lot_ of
changes. ArrayList = .{} -> ArrayList -> .empty also resulted in a lot of
changes, but that's obviously superficial. As is the trimLeft/trimRight ->
trimStart/trimEnd rename.

Locking adopt the `Uncancelable` variants, e.g. mutex.lockUncancelable() to
preserve the error-free signature (and, because cancellation would be something
we'd have to put more thought into).

std.json.ObjectMap is now unmanaged, so the allocator had to be passed along.
However, there's still a deprecated managed variant of MemoryPool, so I switched
to it (we can do a small follow up PR to move to the unmanaged after).

I tried use_llvm = false, but it locks my computer, consuming RAM until MacOS
gives me a popup I've never seen before, begging me to start killing processes.

Agent and the networking stuff saw the most significant changes.
2026-07-22 13:26:03 +08:00
Karl Seguin f0784de015 add http metrics 2026-07-14 11:32:52 +08:00
Halil Durak c967469c49 libcrypto: bind X509_STORE_load_locations 2026-07-04 12:19:09 +03:00
Halil Durak ca1b625d51 libcurl: reintroduce Curl* prefix for function pointer types 2026-07-04 10:01:44 +03:00
Halil Durak 0011f87d82 libcurl: fix VERIFYHOST comment 2026-07-04 10:01:44 +03:00
Halil Durak a8a10b9ba4 libcurl: refactor curl_easy_setopt
Removes lying dead code here and simplifies `curl_easy_setopt` type checking. Also marks passed callbacks as with C calling convention in order to get away from additional function wrapping.
2026-07-04 10:01:43 +03:00
Halil Durak c86dad5430 libcrypto: remove unused utilities 2026-07-02 08:46:22 +03:00
Halil Durak 00123d5102 libcurl: more bindings
* Make curl_easy_setopt aware of SSL_CTX_FUNCTION and SSL_CTX_DATA,
* Add CURLE_* errors.
2026-07-02 08:46:21 +03:00
Halil Durak 6e75a0caa9 libcrypto: bind couple X509, X509_STORE and SSL_CTX helpers 2026-07-02 08:46:20 +03:00
Karl Seguin 01ad869dff Merge pull request #2831 from lightpanda-io/unused_imports
minor: remove unused imports
2026-06-28 07:46:43 +08:00
Karl Seguin 0aaa77c7e6 minor: remove unused imports 2026-06-27 18:16:31 +08:00
Halil Durak 0ddca754a4 URL: move resolver functions to Rust
Implements `url_resolve_with_encoding` and `url_resolve_without_encoding` in Rust; that way, we don't pay the cost of extra `Box`es we allocate during resolving.
2026-06-25 18:05:08 +03:00
Halil Durak a307833e5a URL: introduce url_parse_with_base
This results in creating one less `Box`; hence should be the preferred way when creating a URL object from a base.
2026-06-11 19:18:22 +03:00
Halil Durak 0942b16595 URL: migrate search getter/setter, setHref and toString 2026-06-11 19:18:19 +03:00
Halil Durak 12b3d2c9f4 bind & implement more rust-url utilities 2026-06-11 19:18:19 +03:00
Halil Durak 3f006bf912 add rust-url dependency and bindings for it 2026-06-11 19:18:18 +03:00
Karl Seguin b7c3814ece WPT /WebCryptoAPI/
I threw Claude at WPT's /WebCryptoAPI/ which represents a significant number of
failing cases.

There were a few very low-hanging fruit, like enabling CryptoKey on Worker and
supporting `{name: string}` in addition to just `string` for some functions.

Some of these "fixes" just handle the error case / validation, which tends to
represent a greater number of WPT cases, e.g. some of the importKey algorithms
aren't fully supported, but they still validate the input and return the correct
errors.

To that end, while there should be considerably more passing cases (~42K), some
of these changes merely unlocked more failing cases, so our total case count
should go up.

Claude's summary:

  1. digest {name} object fix (16→80)
  2. Symmetric importKey/exportKey/generateKey (AES, HMAC; raw + jwk) + CryptoKey
  accessors + DataError
  3. EC/OKP importKey usage validation (failure-path)
  4. PBKDF2 + HKDF deriveBits, then deriveKey
  5. ECDH generateKey + import (spki/pkcs8) + deriveBits/deriveKey
  6. AES encrypt/decrypt (CBC/CTR/GCM)
2026-06-08 14:04:15 +08:00
Karl Seguin 320ffa2819 Improve WPT /url/ tests
This is a bit all over the place.

1 - Replace libidn2 with rust-idna. It looks like there are different idna
    profiles, and rust-idna (from the servo project) implements the whatwg
    one. libidn2 would be too strict in some cases and not strict enough in
    others. (Gemini says I could use libidn2 for this, but what it suggested
    didn't work, and I couldn't figure it out myself, and claude insisted it
    _did not_ have the correct implementation for what we want).

2 - We previously only ran a URL through idna if it wasn't ascii. Turns out
    we also need to run it if there's a "xn--" (aka, an IDNA ACE prefix) in
    there. This helps us pass hundreds of WPT cases, and it's pretty cheap.

3 - Implement more of the Area WebAPI. Mostly copied from Anchor.

4 - Add username/password accessor to Anchor/Area

5 - window.open validates the URL (i.e. tries to resolve it and handles the
    error)

6 - Invalid idna conversion maps to a TypeError

7 - Cleanup closed popups on the next tick (like destroyed pages), rather than
    at an interval or on shutdown. This one seems unrelated, but some of these
    tests are opening hundreds (thousands?) of popups and then closing them.
2026-05-29 18:06:44 +08:00
Karl Seguin 875c147783 Main/Network reads CDP socket
Previously, the CDP socket was added to the worker's multi and fully owned
by the worker. While this is simple, it introduced some issues:

1 - Cannot detect a disconnected client during JS processing ( for(;;) )

2 - A blocked worker can cause back-pressure that blocks the client. This can
    cause a deadlock if the worker is blocked waiting for a CDP message

In addition to these 2 problems, there was 1 other serious CDP-related issue:
arbitrary CDP messages could be processed during JavaScript callback. For
example, a Worker calls importScripts while request interception is enabled,
this requires us to tick the HttpClient waiting for the interception response.
But, a client could sent Target.closeTarget, which we'd process and delete the
frame..all while importScripts is still blocked. Assuming importScripts unblocks
everything is a big UAF since the frame (and its workers) were cleared from
closeTarget.

The CDP socket is now read from the network (main) thread and an OTP-style
mailbox is used. The network thread posts message to the Worker's inbox and
signals it to wakeup. This solves #1 and #2. It doesn't directly solve the
reentrancy issue, but it provides the foundation. Specifically, in introduces
a queue for of CDP message and more control over when/how that queue is
processed. At "safe points" (Runner.tick, HttpClient.tick), any message can
be processed. But, when inside a JavaScript callback, we can process only non-
destructive/mutating message. Specifically, we can process only messages related
to request interception.
2026-05-19 20:52:21 +08:00
Karl Seguin 9fe628dd0f Initial idn support
Links to libidn2 and builds libcurl with it. This makes libcurl work, and by
extension browser, work on international domain names, e.g.

zig build run -- fetch "https://räksmörgås.se/"

With it available, we can use it in our WebAPIs which should also support these
domains, e.g:
  testing.expectEqual('xn--rksmrgs-5wao1o.se', new URL('https://räksmörgås.se').hostname);

There is more integration to be done here, but this is a first step.

claude wrote all of the build.zig code.

I don't have a strong opinion about this feature, I just dislike that our WPT
/url/* tests are at 1704 / 9095 and, this is the biggest chunk (although, this
specific commit just does the basic integration and probably won't fix too many
WPT cases directly).
2026-04-28 22:21:27 +08:00
Pierre Tachoire e57b5c645b remove deadcode libcurl.CurlOpenSocketFunction 2026-04-08 14:06:17 +02:00
Lucien Coffe f5cfc4d315 feat: add --block_private_networks and --block_cidrs CLI flags
Block outbound HTTP requests to specified IP ranges before TCP handshake
using libcurl CURLOPT_OPENSOCKETFUNCTION callback. Fires after DNS
resolution, reads resolved IP directly from sockaddr, does bitwise CIDR
comparison. Fail-closed: unknown address families are blocked.

--block_private_networks blocks RFC1918, localhost, link-local, ULA.
--block_cidrs blocks additional comma-separated CIDRs.
IPv4-mapped IPv6 (::ffff:x.x.x.x) is unwrapped to prevent bypass.
2026-04-08 12:10:42 +02:00
Karl Seguin 5733c35a2d WebSocket WebAPI
Uses libcurl's websocket capabilities to add support for WebSocket.

Depends on https://github.com/lightpanda-io/zig-v8-fork/pull/167
Issue: https://github.com/lightpanda-io/browser/issues/1952

This is a WIP because it currently uses the same connection pool used for all
HTTP requests. It would be pretty easy for a page to starve the pool and block
any progress.

We previously stored the *Transfer inside of the easy's private data. We now
store the *Connection, and a Connection now has a `transport` field which is
a union for `http: *Transfer` or `websocket: *Websocket`.
2026-04-04 06:59:28 +08:00
Pierre Tachoire a272a2c314 http: add connect code into auth challenge detection 2026-03-30 15:08:36 +02:00
Nikolay Govorov 16ca8d4b14 Fix cleanup connections in HttpClient 2026-03-27 09:49:03 +00:00
Halil Durak 39352a6bda refactor SubtleCrypto
I've been thinking the implementation here is messy (ever since we added support for it) and thought it would be better to separate each algorithm to their respective files in order to maintain in a long run. `digest` is also refactored to prefer libcrypto instead of std.
2026-03-24 16:04:50 +03:00
Halil Durak 0838b510f8 src/crypto.zig -> src/sys/libcrypto.zig
Now that we have `sys/`, I think this makes more sense.
2026-03-24 16:04:49 +03:00
Nikolay Govorov a6d699ad5d Use common network runtime for telemetry messages 2026-03-17 23:21:57 +00:00
Karl Seguin f1d311d232 Merge pull request #1781 from lightpanda-io/wp/mrdimidium/telemetry-network
Use global connections poll
2026-03-12 13:46:51 +08:00
Nikolay Govorov c4097e2b7e remove dead-code 2026-03-12 03:55:48 +00:00
Nikolay Govorov a95b4ea7b9 Use global connections poll 2026-03-11 05:44:59 +00:00
Nikolay Govorov c891eff664 Use zig allocator for libcurl 2026-03-11 03:34:27 +00:00
Pierre Tachoire 37c34351ee http: handle auth challenge for non-proxy auth 2026-03-09 19:23:36 +01:00
Nikolay Govorov 4c26161728 Move curl C API to type-safe wrapper 2026-02-25 23:29:54 +00:00