Skip to content

Performance and security improvements#176

Open
duncanplatt wants to merge 2 commits intophotodiode:masterfrom
duncanplatt:perf/security-hardening
Open

Performance and security improvements#176
duncanplatt wants to merge 2 commits intophotodiode:masterfrom
duncanplatt:perf/security-hardening

Conversation

@duncanplatt
Copy link
Copy Markdown
Contributor

Summary

Performance

  • Fix onUpdated event filter not being applied — the property filter
    object was outside the addListener() parentheses (comma expression),
    so every tab update fired the handler instead of only the six listed
    properties
  • Replace busy-wait polling with exponential backoff — all while loops
    that spun on getTabValue/getActiveId with no delay now use bounded
    retries (5ms→10ms→20ms…) with timeouts, eliminating CPU spinning and
    potential infinite hangs
  • Add tabs.warmup() on tab hover — pre-renders GPU resources when the
    user hovers a thumbnail, making subsequent tab switches faster
  • Replace (new Date).getTime() with Date.now() across the codebase

Security

  • Add explicit content_security_policy to manifest.json (matches
    Firefox default but makes the policy explicit)
  • Remove unused cookies permission — reduces attack surface
  • Fix undeclared tab variable in remove() — missing const caused a
    strict-mode ReferenceError that silently broke the "were tabs actually
    closed?" verification
  • Validate message sender — background message handler now rejects
    messages from external extensions via sender.id check
  • Add error handling for JSON.parse (backup restore) and decodeURI
    (tab tooltips) to prevent crashes on malformed input

Test plan

  • Open Panorama View and verify tab groups display correctly
  • Create, rename, and remove tab groups
  • Hover over tab thumbnails, then click to switch — confirm switching
    feels responsive
  • Drag tabs between groups
  • Move tabs between windows and confirm they appear in the correct group
  • Use keyboard shortcuts to cycle through groups (Ctrl+Alt+W / Q)
  • Save and restore a backup file
  • Attempt to load a non-JSON file as backup — should show error, not crash
  • Verify on both Firefox < 138 (polyfill path) and Firefox ≥ 138 (native
    tabGroups API) if possible

Performance:
- Fix onUpdated filter in view.js not being passed to addListener (comma
  expression instead of second argument), causing all tab updates to fire
  the handler instead of only filtered properties
- Replace busy-wait polling loops in addon.tabs.js and addon.tabs.events.js
  with exponential backoff (5ms–160ms), preventing tight spinning on the
  sessions API and eliminating potential infinite hangs
- Add tabs.warmup() on tab thumbnail hover to pre-render GPU resources
  for faster tab switching (Firefox 61+, with feature detection)
- Replace (new Date).getTime() with Date.now() to avoid unnecessary
  object allocation

Security:
- Add explicit content_security_policy to manifest.json
- Remove unused cookies permission from manifest.json
- Fix undeclared variable in addon.tabGroups.js remove() that caused the
  tab-removal verification to fail silently under strict mode
- Validate sender.id in background message handler to reject messages
  from external extensions
- Add try/catch around JSON.parse when loading backup files to prevent
  crashes on malformed input
- Add try/catch around decodeURI in tab tooltips to handle malformed
  percent-encoded URLs gracefully

Also adds undefined guards in activated() to prevent calling
toggleVisibleTabs with an undefined groupId (which would hide all tabs)
and setActiveId (which would trigger a lock leak in the mutex).
The strict sender.id !== browser.runtime.id check rejected messages
from the options page when embedded in about:addons, breaking backup
save/load and interval settings. Loosen to only reject messages where
sender.id is explicitly set to a different extension's ID.
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.

1 participant