Skip to content

Add embed:// scheme for serving trusted local content - #34

Merged
maxim-productengine merged 7 commits into
masterfrom
maxim/embed-scheme
Jul 31, 2026
Merged

Add embed:// scheme for serving trusted local content#34
maxim-productengine merged 7 commits into
masterfrom
maxim/embed-scheme

Conversation

@maxim-productengine

Copy link
Copy Markdown
Contributor

Added a new custom embed:// scheme served entirely by Dullahan from an on-disk root that the Viewer configures. Content is treated by CEF as a proper secure origin.

Registry allowlist. The host configures a registry of allowed paths. Exact-match paths are supported for individual files; entries ending in / are treated as directory prefixes. Any request that doesn't match returns 404 without touching disk.
Related Viewer-side API: setEmbedSchemeRoot(root_dir) and setEmbedRegistry(allowed_paths) to configure the scheme handler.

Bridge scoping. The window.JSONtoCPP JS bridge is now injected only on frames whose URL is under embed://. Ordinary web pages don't see the bridge. Each JS→C++ message also carries the calling frame's URL so the host can verify origin.

Recursive-inheritance enforcement. A browser whose top-level document is an embed:// page may only load embed:// or data: sub-resources - no external iframes, images, scripts, stylesheets, fetches, or beacons. Conversely, a browser NOT running embed:// content cannot fetch embed:// resources. Applied via OnBeforeResourceLoad; enforced by tracking the trust context set in OnBeforeBrowse to avoid a UI/IO thread race that would otherwise misclassify sub-resources fired right after a navigation commits.

Navigation lockdown. Top-level navigation into embed:// from a user-clicked link or an HTTP redirect is rejected. Loading embed:// requires an explicit LoadURL call from the host.

@callumlinden callumlinden left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great - nice work. Just a couple of minor comments:

  • I see references to the scheme name and format in many places, in different files. E.G.

    const char* kEmbedScheme = "embed";
    const char* kEmbedSchemePrefix = "embed://";
    
  • Would it be worth centralizing that in a header perhaps so that it only needs to be changed once?

  • See a lot of places where the lowercase version of a string is created. Is that okay for non-ascii strings (I think it is - just checking) and worth using a single 'canonical' ToLower() function like:

    std::string text = "HeLLo WoRLd!";
    auto lower_text = text
                  | std::views::transform([](unsigned char c) { return std::tolower(c); })
                  | std::ranges::to<std::string>(); // Converts view back to std::string
    std::cout << lower_text; // outputs: hello world!
    
  • Might need to add entries in the mime_for_path() function for other file types in Garfield's 3p package - E.G. TypeScript .ts

@maxim-productengine

Copy link
Copy Markdown
Contributor Author

Thanks, it makes sense.
I'll add one more commit with the changes you suggested before merging.

@maxim-productengine
maxim-productengine merged commit 3a2cdb4 into master Jul 31, 2026
10 checks passed
@maxim-productengine
maxim-productengine deleted the maxim/embed-scheme branch July 31, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants