Repository navigation
fix(webapi): protect native records with private types - #404
jderochervlk wants to merge 10 commits into
Conversation
Upgrade the compiler baseline before continuing the private-record migration in #404. ReScript 13.0.0-alpha.7 includes rescript-lang/rescript#9125, which rejects coercion from another type into a private record—the loophole reproduced on alpha.5 in #403. Pin the development compiler and raise the minimum peer version to alpha.7, update the lockfile and installation guidance, and reject the former alpha.5 baseline in packed-consumer checks. Add a regression for forged Response coercion alongside positive coverage for native construction, direct field reads, outward coercion, and the existing File-to-Blob helper. This does not introduce package-wide native-record privacy. The upgrade also requires a concrete typed-array operation in the ImageData fixture and support for the compiler's new documentation parameter/type schema. Preserve rendered signatures and type links, including callbacks, tuples, and generic parameters. The changes across 40 existing ReScript files are the new compiler's formatting output. Alpha.7 no longer supports native compilation on Intel Macs (`darwin-x64`); the migration notes and project status call out that compatibility break. Refs #403. This is the prerequisite branch for #404, not the private-record migration itself.
|
Updated through Local validation passed on Node 26: An independent source review identified readonly-property setters, a WaveShaper typed-array mismatch, the missing template empty-string state, inherited conversion gaps, and lost throwing annotations. Those concrete findings were corrected and covered by the subsequent local checks. This is not independent approval of all later edits or a package-wide soundness guarantee. The main remaining public-functor policy blocker was reproduced separately against the packed alpha.7 package: module Receiver = {type t = {getRootNode: unit => string}}
module FakeNode = WebAPI.Node.Impl(Receiver)
let forged: WebAPI.Node.t =
FakeNode.getRootNode({getRootNode: () => "not a node"})This compiles without unsafe casts, raw JavaScript, consumer externals, or |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Updated to The agreed merge contract is private-record construction/update/coercion protection plus audited supported writes and concrete native conversions—not package-wide native-instance soundness. The public functor boundary is now a separate follow-up, #417; the remaining broader callback/union typing work stays under #403. The standalone hardening also completes the previously listed DOMImplementation, HTMLOptionsCollection, and AudioWorklet conversion/write paths, with packed consumer and Chromium coverage. An independent review of this revision found no blocking regressions under the narrowed contract. All local checks passed on Node 26: format, build, Node tests, all 36 feature definitions and narrow-feature isolation probes, negative and packed consumers, four Chromium tests, docs build/link checks, and release validation. The updated Playwright browser was installed into the ignored worktree-local cache for validation. CI is rerunning on this revision; merging into main is still a separate maintainer action. |
|
Closing in favor of the preferred consumer API: direct field reads and direct mutation of writable native properties. The private-record migration in this PR requires explicit setter functions on ReScript alpha.7, which is not the API direction we want. We are not landing that migration or its setter-based contributor rules. Independent binding fixes are tracked in #418 for extraction into smaller, reviewable PRs: checked union narrowing, concrete native result/handle types, constructible NodeFilter callbacks, and MessageEvent default payload typing. #418 also links the existing #403 and #417 work and records that their plans must preserve direct mutation rather than assume this setter migration will proceed. The branch remains available as reference; this PR is closed without merging. |
Protect native-record construction and audited property writes on ReScript 13.0.0-alpha.7. Native instances retain direct field reads and use typed setters for supported mutation; caller-owned options, initializers, and callback dictionaries remain constructible.
Before and after
Write native properties through typed setters; keep direct reads
Before:
After:
The setter writes the native JavaScript property; it does not create a wrapper or copy. Direct field reads stay available. Use the supported setters instead of private-field assignment, which produces warning 111 on alpha.7.
Construct real native instances instead of record-update copies
Before, the public URL record allowed this:
That produces an ordinary JavaScript object, not a new native URL. After, the record update is rejected; create a native URL and set its property instead:
This restriction applies to browser-owned instance records, not caller-owned dictionaries. Options and initializers remain constructible, for example:
Keep identity upcasts tied to concrete native receiver types
Before, an upcast inherited from a public generic functor could turn an unrelated value into a native type:
After,
asBlobis no longer provided byBlob.Impl. Use the concrete helper for an actual native File:WebAPI.File.asBlob("not a Blob")is a type error. These helpers are zero-cost upcasts, not runtime validators. They also provide supported derived-to-base conversions where alpha.7 rejects structural:>coercions into private records. This does not fix every native-returning method in generic functors; that broader boundary remains follow-up #417.Check union values before narrowing them to native instances
Before, the intersection-root projection was an unchecked identity cast, even though a root can be an Element, Document, or null:
After, it returns an option based on a native-instance check:
IntersectionObserverRoot.toDocument,FillStyle.toCanvasGradient, andFillStyle.toCanvasPatternsimilarly return options. These checks recognize native instances in the current realm, not objects from every iframe or realm.Scope
Private backing declarations and public record views reject ordinary literals, record-update copies, and structural coercion into protected types. Concrete-receiver upcasts preserve supported inherited operations without unrestricted identity casts in public
Implfunctors. This is a compile-time record construction/write contract, not a package-wide native-instance soundness or security guarantee.The migration includes checked Canvas-style and intersection-root downcasts, native stream handle identities, accurate performance-entry arrays, a constructible NodeFilter callback dictionary, nullable default MessageEvent payloads, and a concrete media-key access result. Public media, DOM-node, geometry, options-collection, XML/document-type, and AudioWorklet paths retain supported reads, writes, and conversions.
The branch incorporates current main, including the History/Location, DOMTree/CSSOMCore, and narrow data feature splits. Privacy and typed setters remain intact at the new canonical locations, without broadening those feature dependencies. The inventory covers 294 public modules, with explicit backing/view classifications, abstract identities, public setters, and constructible exceptions. Packed consumers and native browser workflows cover the changed boundaries; declaration checks alone are not treated as proof that every binding is sound.
Follow-up work, not merge prerequisites
sources.publicconfiguration does not enforce that boundary on alpha.7. Library-only alternatives and compiler project-scoped visibility are being investigated separately.This PR can be reviewed and merged independently of the
Implredesign. It partially addresses #403 and does not close the broader issue automatically.