Skip to content

WASM: declared sha256 and fallback are never used — assets are trusted unverified #4025

Closed

Description

@zackees

Defect

Every asset declaration carries a sha256, the loader reads it, and nothing ever checks it.

{ "data/track.mp3": { "sha256": "cadd2666...", "url": "https://raw.githubusercontent.com/..." } }

sha256 appears exactly twice in index.ts -- both in doc comments:

71:  * `{url, sha256, fallback}`. sha256 and fallback are parsed but NOT enforced
754: * @param {Object} manifest - path -> {url, sha256, fallback, size?}

So an asset fetched over the network is handed to the sketch unverified, while the correct digest sits in memory beside it. fbuild treats sha256 as mandatory precisely because its cache is content-addressed; the browser path takes the same declaration and ignores it.

fallback is in the same position: declared, parsed, never used on failure.

Why it matters more now

Assets now populate fl::getEmbeddedFs(), i.e. they are the filesystem the sketch reads. Corruption or a wrong-content URL is indistinguishable from correct data at runtime. SubtleCrypto.digest('SHA-256', ...) is available in any browser that can run this build, so the cost is a hash over bytes already in memory.

Fix

Research: hashing while streaming vs. after -- an 8.9MB asset is already fully buffered in FileData, so a second pass may be simpler than an incremental digest, but it doubles the peak walk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions