Skip to content

Provide a boundary between Components and DOM #4295

Open
@naugtur

Description

@naugtur

I'd like to open up a conversation about supporting use-cases where an application's UI is composed from potentially untrusted code.
With the proliferation of malware in JavaScript supply chain it's a concern that we've been trying to address at LavaMoat by isolating each package into an independent scope with varying access to globals etc. based on a per-package policy (see more: links below)
We've been successful in isolating packages, but the ability to access DOM nodes, and on them ownerDocument and alike can undermine those defenses.

I an pursuing an approach where using the fact that modern components rarely need direct DOM access, we could block leaking of any DOM references into components if only a boundary can be put in place in the DOM diffing code.
In my reading of Preact codebase I was not successful in finding such boundary though. Internal and external use of DOM references doesn't seem strongly separated, so if I were to wrap or deny DOM references, it would also affect Preact internals.

I'm requesting help in identifying places where Preact would expose DOM references to components being rendered and introducing a mechanism to intercept them.

the actual feature request
I imagine it being a factory for creating a render function that accepts configuration including a function that gets called with each DOM reference being assigned/passed to the component representation (result of calling the h function) and returns what should be passed on as the DOM reference. Even if it's an empty object.

I just noticed options.vnode which might be all I need to implement it myself, but the conversation would still be useful to have.

Alternatively, but I can imagine it being too major of a refactor, we could look into separating virtual DOM and real DOM into two distinct layers that communicate via a channel that's potentially even JSON serializable. I guess this ask comes way too early before the pendulum swings from SSR to clientside only + p2p.

Context:
https://github.com/LavaMoat/LavaMoat
https://www.youtube.com/watch?v=U68zPZSc7nk

[edit]
Preact is so beautifully pluggable that I might soon have a prototype and my ask might change into asking whether it's a sound approach.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions