youtube icon indicating copy to clipboard operation
youtube copied to clipboard

[Architecture Report] [Performance] [Privacy] Extension storage loaded (exposed) to YouTube page context

Open xryj920 opened this issue 5 months ago • 2 comments

Hi there,

I'm a student security researcher. I recently reviewed your Chrome extension "'Improve YouTube!' (for YouTube & Videos)" (ID bnomihfieiccainjcjblhegjgglakjdd, version 4.2026) during good-faith analysis, and I found a storage exposure issue that I wanted to report privately.

I'm not seeking any reward of any kind — I only hope this helps you review and tighten the extension if you agree this is unintended. A short acknowledgement that the report was received and reviewed would genuinely mean a lot to me.

Issue: On YouTube pages, the extension reads its entire chrome.storage.local contents and copies them into page-visible channels. This lets arbitrary YouTube page scripts, and any other extension with a content script on https://www.youtube.com/*, read data that normally belongs only to the Improve YouTube extension's private storage.

Definition: The content script reads all storage keys and values, then exposes them in two forms:

  • As DOM attributes on document.documentElement (each key becomes it-<key>).
  • As a storage-loaded message written into a hidden DOM node and broadcast via a CustomEvent.

There is no filtering. The entire storage object is included.

Usage:

1. Manifest injection

"content_scripts": [
  {
    "all_frames": true,
    "js": [
      "js&css/extension/core.js",
      "js&css/extension/functions.js",
      "...",
      "js&css/extension/init.js"
    ],
    "matches": ["https://www.youtube.com/*"],
    "run_at": "document_start"
  }
],
"host_permissions": ["https://www.youtube.com/*"],
"permissions": ["contextMenus", "storage"]

2. Hidden message node creation (js&css/extension/core.js)

extension.messages.create = function() {
    this.element = document.createElement('div');
    this.element.id = 'it-messages-from-extension';
    this.element.style.display = 'none';
    document.documentElement.appendChild(this.element);
};

3. Sending a message writes JSON into that DOM node and fires a page-level event

extension.messages.send = function(message) {
    if (typeof message === 'object') {
        message = JSON.stringify(message);
    }

    this.queue.push(message);

    if (this.queue.length === 1) {
        this.element.textContent = message;
        document.dispatchEvent(new CustomEvent('it-message-from-extension'));
    }
};

4. Storage loading — the core of the exposure

extension.storage.load = function(callback) {
    chrome.storage.local.get(function(items) {
        extension.storage.data = items;

        for (const key in items) {
            document.documentElement.setAttribute(
                'it-' + key.replace(/_/g, '-'),
                items[key]
            );
        }

        extension.events.trigger('storage-loaded');
        extension.messages.send({
            action: 'storage-loaded',
            storage: items
        });

        if (callback) {
            callback(extension.storage.data);
        }
    });
};

5. Storage change listener also exposes new values

chrome.storage.onChanged.addListener(function(changes) {
    for (var key in changes) {
        var value = changes[key].newValue;

        document.documentElement.setAttribute(
            'it-' + key.replace(/_/g, '-'),
            value
        );

        extension.messages.send({
            action: 'storage-changed',
            key,
            value
        });
    }
});

6. Page-side script reads the exposed storage (js&css/web-accessible/core.js)

document.addEventListener('it-message-from-extension', function() {
    var provider = document.querySelector('#it-messages-from-extension');

    if (provider) {
        var message = provider.textContent;

        document.dispatchEvent(new CustomEvent('it-message-from-extension--readed'));

        try {
            message = JSON.parse(message);
        } catch (error) {
            console.log(error);
        }

        if (message.action === 'storage-loaded') {
            ImprovedTube.storage = message.storage;
        }
    }
});

Why this matters: The extension's chrome.storage.local can hold values that are not just harmless UI preferences. For instance, the settings page allows storing a YouTube API key (google-api-key) and a password for the extension (password):

// Settings: API key field
textField: {
    component: 'text-field',
    storage: 'google-api-key',
    value: '<default API key present in source>',
    rows: 1,
    lineNumbers: false
}

// Settings: password field
const passwordInput = document.getElementById('password-input');
passwordInput.placeholder = "Enter password";
passwordInput.value = satus.storage.get("password") || '';
...
input: function(event) {
    satus.storage.set("password", event.target.value);
}

If a user has set a custom API key, an extension password, or any other private value, that data appears in the storage-loaded object and as DOM attributes. A malicious extension would not normally be able to read another extension's chrome.storage.local, but here the entire storage is copied into the shared YouTube page context. Any other extension with a content script on YouTube can passively collect it.

Reproduction:

  1. Install Improve YouTube.
  2. Set a recognizable value in the password field or API key field.
  3. Open https://www.youtube.com/.
  4. Run this in the page context (or another extension's content script):
document.addEventListener("it-message-from-extension", () => {
    const node = document.querySelector("#it-messages-from-extension");
    console.log(node && node.textContent);
});
  1. When the extension sends storage-loaded, the listener receives the full serialized storage object.

I am not claiming that every stored preference is sensitive. The issue is that the extension exposes the entire private storage without filtering, and that storage can contain values users would not expect YouTube pages or other extensions to see.

Recommendation:

  • Stop sending the full chrome.storage.local object into the page context. If the page-side script needs a few settings, whitelist only the non-sensitive keys.
  • Keep keys like password, google-api-key, account-related values, tokens, or anything user-provided strictly inside the isolated extension/content-script world. They should not be set as DOM attributes or placed in the #it-messages-from-extension node.
  • Consider separating display preferences (which the page may legitimately need) from private extension settings, so the page bridge cannot accidentally leak sensitive values now or in the future.

Thank you very much for taking the time to review this. Even a brief confirmation that you received the report would be deeply appreciated.

xryj920 avatar Jun 29 '26 03:06 xryj920

hi! and thank you for caring @xryj920

extension.storage.load should not load videos lists for speed too.

most of the data is toggles only but some have a history of video IDs (maybe more in future.)

I found a storage exposure issue that I wanted to report privately.

publicly?

ImprovedTube2 avatar Jun 29 '26 19:06 ImprovedTube2

Thanks for the clarification! I agree that the video history is the most relevant example today, and my main concern was that the entire storage object is exposed by design, which could unintentionally include more user data in the future as the extension evolves.