Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 36 ยท Permissions and Security

Least Privilege, Privacy and Data Handling

Reduce what your Chrome extension can touch with narrow matches, activeTab and declarative alternatives, handle user data responsibly, and prepare the privacy disclosures the Web Store requires.

Security is not only about stopping attackers. It is also about collecting only what you need and being honest about it. Users install extensions with broad powers on the strength of trust, and Google's review and privacy policies expect you to earn it. This lesson gathers the habits that reduce your risk surface: narrower access, less data and clear disclosure.

Prefer narrower mechanisms

Many "I need <all_urls>" designs have a smaller alternative:

You want to... Instead of broad access, use
Act on the page when the user clicks activeTab
Run a script on a few known sites content_scripts.matches for those sites only
Block or redirect requests declarativeNetRequest rules (no page-content access)
Change the page for the user on demand chrome.scripting.executeScript after a click
Talk to your own API host_permissions for that API origin only
Handle search from the address bar the omnibox API

declarativeNetRequest deserves a note: the browser applies your rules itself, so your extension does not see the content of the requests. That is why Manifest V3 pushes ad blockers and header changes toward it, and why it needs far fewer warnings than webRequest.

JSON
{
  "permissions": ["declarativeNetRequest"],
  "declarative_net_request": {
    "rule_resources": [{ "id": "rules", "enabled": true, "path": "rules.json" }]
  }
}

Narrow content scripts

A content script declared for all sites runs on every page, which costs memory, slows browsing and raises the stakes of any bug.

JSON
{
  "content_scripts": [{
    "matches": ["https://docs.example.com/*"],
    "exclude_matches": ["https://docs.example.com/admin/*"],
    "js": ["content.js"],
    "run_at": "document_idle"
  }]
}

If the script is only needed sometimes, do not declare it. Inject it from the worker when the user asks, or register it dynamically for hosts the user chooses with chrome.scripting.registerContentScripts plus an optional host permission.

Collect less, keep less

Ask for each piece of data: do we need it, how long do we keep it, and where does it go?

  • Do not collect what you do not use. Not the full URL if the domain is enough; not the page text if a count is enough.
  • Keep data on the device (chrome.storage.local) when you can. Process locally instead of uploading.
  • Minimise retention. Delete old records automatically, and offer a "clear my data" button.
  • No silent telemetry. If you measure usage, make it anonymous, minimal, and disclosed.
  • No sale or transfer of user data for unrelated purposes; that is prohibited by the store's Limited Use rules.
  • Encrypt in transit with HTTPS, and never log tokens.
Minimise what you keep

Handle sensitive pages carefully

Some pages contain information that must never leave the browser: banking, health, email, password managers. If your extension reads page content, skip those sites by design (exclude patterns), do not scrape form fields, and never read password inputs. Do not record keystrokes. Extensions that do are among those removed from the store.

The privacy policy and disclosures

When you publish, the Web Store asks two things:

  1. Data usage disclosures: tick which categories you handle (personally identifiable information, health, financial, authentication, personal communications, location, web history, user activity, website content) and certify that you follow the Limited Use requirements.
  2. A privacy policy URL, required when you handle user data of any of those kinds.

Write the policy in plain language: what you collect, why, where it goes, how long you keep it, how users can delete it, and how to contact you. Match it exactly to what the code does, because reviewers compare them. See Publishing: preparing for the store.

A quarterly audit

Audit your extension

Permissions Is each one still used?
Hosts Can any pattern be narrower?
Data Do we keep less than before?
Dependencies Any outdated or unused?

Remove, then ship a patch.

1 / 2

Removing a permission is easy; adding one later forces every user to re-approve, and Chrome disables the extension until they do. That is another reason to start small and request more only with a clear feature behind it.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why is declarativeNetRequest considered a privacy-friendly choice over webRequest for blocking?

    The rules are enforced by the browser, so the extension needs less access to the user's traffic.
  2. 2. A content script is needed only on docs.example.com. What is the best configuration?

    Narrow matches limit where the script runs and what a bug could touch.
  3. 3. What happens when an update adds a new warning-level permission?

    Users must re-approve new permissions that carry warnings, and many never do, so avoid adding them lightly.
  4. 4. Which practice follows data minimisation?

    Collect only what the feature needs and delete it when it is no longer useful.

Summary

  • Replace broad access with activeTab, narrow matches, on-demand injection and declarativeNetRequest.
  • Collect less, store locally, prune old data and offer a way to delete it.
  • Stay away from sensitive pages and never read passwords or keystrokes.
  • Fill in the Web Store data disclosures and publish an accurate privacy policy.

Next: Debugging Every Extension Context