1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-28 07:13:29 +00:00
Alex 1db601b82f [PM-30718] add IndexedDB storage service for phishing data (#18344)
* add PhishingIndexedDbService for IndexedDB storage

Add a dedicated IndexedDB storage service for phishing detection data.
This service provides save, load, and clear operations using IndexedDB
instead of chrome.storage.local to avoid broadcast overhead, size
limitations, and JSON serialization cost for large datasets.

* add unit tests for PhishingIndexedDbService

Add comprehensive tests for save, load, and clear operations with
mocked IndexedDB. Tests cover success cases, error handling, and
database initialization with object store creation.

* add PhishingIndexedDbService core structure

- Add IndexedDB service with per-operation database opening
- Define PhishingUrlRecord type for row storage
- Include clearStore helper for atomic data replacement
- Service worker safe: no cached connections

* add saveUrls with chunked writes

- Add PhishingUrlRecord type for row storage
- Store each URL as individual row
- Chunk writes at 50K per transaction for responsiveness
- Atomic replacement: clear then save

* add hasUrl for lookups

- Direct IndexedDB index lookup via keyPath
- Returns boolean, handles errors gracefully

* add loadAllUrls with cursor iteration

- Cursor-based bulk load for fallback scenarios
- Memory-efficient: no intermediate array duplication
- Returns empty array on error

* add saveUrlsFromStream for memory efficiency

- Stream directly from fetch response body
- Parse newline-delimited URLs incrementally
- Reuse chunked save infrastructure

* update PhishingIndexedDbService tests

- Replace blob-based tests with row-per-URL API tests
- Test saveUrls, hasUrl, loadAllUrls, saveUrlsFromStream
- Verify chunked writes and cursor iteration
- Use stream/web ReadableStream with type cast for Node.js compatibility

* use proper URL syntax and cleanup global state

Update test data to use proper URL syntax with https:// prefix to match
real phishing.database format. Add cleanup of global.indexedDB in
afterEach to prevent test pollution.

* improve stream processing correctness and efficiency

- Move decoder.decode() before done check with { stream: !done } to flush properly
- Use array reassignment instead of splice() for O(1) chunk clearing
- Use single trim via local variable to avoid double-trim
- Centralize URL cleaning in saveChunked(), simplify saveChunk()
- Use explicit urls.length > 0 comparison

* duplicate urls test

* split final buffer by newlines
2026-01-21 12:55:14 -08:00
2024-01-30 06:50:54 -08:00
2021-12-21 15:43:35 +01:00
2022-03-15 15:39:14 -04:00

Bitwarden

GitHub Workflow browser build on main GitHub Workflow CLI build on main GitHub Workflow desktop build on main GitHub Workflow web build on main gitter chat


Bitwarden Client Applications

This repository houses all Bitwarden client applications except the mobile applications (iOS | android).

Please refer to the Clients section of the Contributing Documentation for build instructions, recommended tooling, code style tips, and lots of other great information to get you started.

We're Hiring!

Interested in contributing in a big way? Consider joining our team! We're hiring for many positions. Please take a look at our Careers page to see what opportunities are currently open as well as what it's like to work at Bitwarden.

Contribute

Code contributions are welcome! Please commit any pull requests against the main branch. Learn more about how to contribute by reading the Contributing Guidelines. Check out the Contributing Documentation for how to get started with your first contribution.

Security audits and feedback are welcome. Please open an issue or email us privately if the report is sensitive in nature. You can read our security policy in the SECURITY.md file.

Description
No description provided
Readme 1.1 GiB
Languages
TypeScript 81.8%
HTML 12.6%
SCSS 2.3%
JavaScript 1.6%
MDX 0.9%
Other 0.7%