mirror of
https://github.com/morluto/rea
synced 2026-10-28 15:07:26 -04:00
fix(javascript): stop reading media preload attributes as Electron preloads
HTML audio and video elements have their own `preload` attribute ("none",
"metadata", "auto"). A React renderer compiles `<audio preload="metadata">`
to `jsx("audio", { preload: "metadata" })`, and the `property:preload`
heuristic reported it as an Electron preload script named `metadata`.
Skip `preload` properties in the props object of a call whose first
argument is the static tag `audio` or `video`. The callee is not checked,
because minified element factories have arbitrary names.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XPY2GmufMNGQKoEgRUx1pd
This commit is contained in:
@@ -65,6 +65,8 @@ export const inspectCall = (
|
||||
addReference(context, { node, kind: "service-worker", specifier: first });
|
||||
inspectEndpointCall(node, name, first, context);
|
||||
inspectStorageCall(node, name, first, context);
|
||||
if (first === "audio" || first === "video")
|
||||
noteMediaElementPreloads(node, accumulator);
|
||||
if (name.endsWith("loadFile") && first !== undefined)
|
||||
addLocatedFinding(context, {
|
||||
collection: accumulator.roles,
|
||||
@@ -95,6 +97,23 @@ export const inspectCall = (
|
||||
});
|
||||
};
|
||||
|
||||
// Element factories such as jsx("audio", props) and createElement("video",
|
||||
// props) carry the HTML media `preload` hint ("none", "metadata", "auto"),
|
||||
// which never names an Electron preload script.
|
||||
const noteMediaElementPreloads = (
|
||||
node: JavaScriptCallLike,
|
||||
accumulator: AnalysisAccumulator,
|
||||
): void => {
|
||||
const props = node.arguments[1];
|
||||
if (!t.isObjectExpression(props)) return;
|
||||
for (const property of props.properties)
|
||||
if (
|
||||
t.isObjectProperty(property) &&
|
||||
semanticStaticPropertyName(property.key, property.computed) === "preload"
|
||||
)
|
||||
accumulator.mediaElementPreloads.add(property);
|
||||
};
|
||||
|
||||
const requireCallSpecifier = (
|
||||
node: JavaScriptCallLike,
|
||||
name: string,
|
||||
@@ -201,6 +220,7 @@ export const inspectRoleProperty = (
|
||||
context: FindingContext,
|
||||
): void => {
|
||||
if (semanticStaticPropertyName(node.key, node.computed) !== "preload") return;
|
||||
if (context.accumulator.mediaElementPreloads.has(node)) return;
|
||||
const path = staticPath(node.value);
|
||||
if (path === undefined) return;
|
||||
addLocatedFinding(context, {
|
||||
|
||||
Reference in New Issue
Block a user