Skip to content

Conversation

quexten
Copy link
Contributor

@quexten quexten commented Sep 4, 2025

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-25458

📔 Objective

There is currently a set of bugs that is hard to track down, and blocks vault initialization. This has two causes:

  • Decrypt failures throw, as per the public contract of encrypt service. This is not handled by callers at all in many cases, expecting decryption to work
  • Stack traces are made useless by closures & rx-js

Each callsite has to appropriately handle the public contract. In this case, the PR adds stubs that at least log an error and the callsite for debugging, and re-throw. This can be replaced by the owning teams, once they handle the errors appropriately with domain specific logic. That is left out of this PR since I cannot make assumptions about what the appropriate behavior is. Roughly, it should not block the app from loading (probably), and set appropriate UI values, while at the same time ensuring default values don't leak back into being re-encrypted, when an item is edited.

Alternatively, most of the covered code is also being migrated to the SDK, so we can drop the TS code entirely, and handle in rust, which has much nicer tooling. But we do want the debuggability in the meantime to fix existing issues.

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@quexten quexten changed the title Add error handling stubs for critical decrypt paths Add error handling stubs & logging for critical decrypt paths Sep 4, 2025
Copy link
Contributor

github-actions bot commented Sep 4, 2025

Logo
Checkmarx One – Scan Summary & Details339da842-dcc3-4198-9510-83cabdadccbe

New Issues (5)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
HIGH CVE-2025-9864 Npm-electron-36.4.0
detailsRecommended version: 38.0.0
Description: Use after free in V8 in Google Chrome prior to 140.0.7339.80 allowed a remote attacker to potentially exploit heap corruption via a crafted HTML pa...
Attack Vector: NETWORK
Attack Complexity: LOW

ID: cU2tRv1Qu4%2FqkVvt0GRgfgfdq6QCUk3FaC893RWnR3k%3D
Vulnerable Package
MEDIUM CVE-2025-9865 Npm-electron-36.4.0
detailsDescription: Inappropriate implementation in Toolbar in Google Chrome on Android prior to 140.0.7339.80 allowed a remote attacker who convinced a user to engage...
Attack Vector: NETWORK
Attack Complexity: LOW

ID: 8YwQDBmEmsjpfM81ZPHL5FB498%2Bcq96wmhkRktOujPg%3D
Vulnerable Package
MEDIUM Missing_HSTS_Header /apps/cli/src/auth/commands/login.command.ts: 699
detailsThe web-application does not define an HSTS header, leaving it vulnerable to attack.
ID: WuPrsECJ9pM%2BNBowkuhQEthv7LA%3D
Attack Vector
LOW Client_Use_Of_Iframe_Without_Sandbox /apps/browser/src/autofill/overlay/inline-menu/pages/menu-container/autofill-inline-menu-container.ts: 68
detailsThe application employs an HTML iframe at whose contents are not properly sandboxed
ID: eC9rGjAaHK3DyR9G%2BtM7mnxXkNU%3D
Attack Vector
LOW Client_Use_Of_Iframe_Without_Sandbox /apps/browser/src/autofill/overlay/inline-menu/iframe-content/autofill-inline-menu-iframe.service.ts: 87
detailsThe application employs an HTML iframe at whose contents are not properly sandboxed
ID: mfl0i7Wn6Zj3Z71nx1CQn0bYd3s%3D
Attack Vector
Fixed Issues (2041)

Great job! The following issues were fixed in this Pull Request

Severity Issue Source File / Package
MEDIUM HttpOnly_Cookie_Flag_Not_Set /apps/web/src/connectors/sso.spec.ts: 42
MEDIUM HttpOnly_Cookie_Flag_Not_Set /apps/web/src/connectors/sso.spec.ts: 26
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/angular/src/vault/vault-filter/models/vault-filter.model.spec.ts: 121
MEDIUM Use_Of_Hardcoded_Password /libs/angular/src/vault/vault-filter/models/vault-filter.model.spec.ts: 122
MEDIUM Use_Of_Hardcoded_Password /libs/angular/src/vault/vault-filter/models/vault-filter.model.spec.ts: 122
MEDIUM Use_Of_Hardcoded_Password /libs/angular/src/vault/vault-filter/models/vault-filter.model.spec.ts: 122
MEDIUM Use_Of_Hardcoded_Password /libs/angular/src/vault/vault-filter/models/vault-filter.model.spec.ts: 121
MEDIUM Use_Of_Hardcoded_Password /libs/angular/src/vault/vault-filter/models/vault-filter.model.spec.ts: 121
MEDIUM Use_Of_Hardcoded_Password /libs/angular/src/vault/vault-filter/models/vault-filter.model.spec.ts: 122
MEDIUM Use_Of_Hardcoded_Password /libs/angular/src/vault/vault-filter/models/vault-filter.model.spec.ts: 121
MEDIUM Use_Of_Hardcoded_Password /apps/browser/src/vault/popup/components/vault-v2/view-v2/view-v2.component.spec.ts: 63
MEDIUM Use_Of_Hardcoded_Password /apps/browser/src/vault/popup/components/vault-v2/view-v2/view-v2.component.spec.ts: 63
MEDIUM Use_Of_Hardcoded_Password /apps/browser/src/vault/popup/components/vault-v2/view-v2/view-v2.component.spec.ts: 63
MEDIUM Use_Of_Hardcoded_Password /apps/browser/src/vault/popup/components/vault-v2/view-v2/view-v2.component.spec.ts: 63
MEDIUM Use_Of_Hardcoded_Password /apps/browser/src/vault/services/at-risk-cipher-badge-updater.service.spec.ts: 30
MEDIUM Use_Of_Hardcoded_Password /apps/browser/src/vault/services/at-risk-cipher-badge-updater.service.spec.ts: 30
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /apps/browser/src/vault/popup/components/vault-v2/view-v2/view-v2.component.spec.ts: 63
MEDIUM Use_Of_Hardcoded_Password /apps/browser/src/autofill/background/notification.background.spec.ts: 938
MEDIUM Use_Of_Hardcoded_Password /apps/browser/src/autofill/background/notification.background.spec.ts: 1025
MEDIUM Use_Of_Hardcoded_Password /apps/browser/src/autofill/background/notification.background.spec.ts: 858
MEDIUM Use_Of_Hardcoded_Password /apps/browser/src/autofill/background/notification.background.spec.ts: 810
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/utils/cipher-view-like-utils.spec.ts: 184
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/utils/cipher-view-like-utils.spec.ts: 184
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/utils/cipher-view-like-utils.spec.ts: 178
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/utils/cipher-view-like-utils.spec.ts: 178
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/services/default-cipher-encryption.service.spec.ts: 33
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/services/default-cipher-encryption.service.spec.ts: 34
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/services/default-cipher-encryption.service.spec.ts: 35
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/services/default-cipher-encryption.service.spec.ts: 65
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/services/default-cipher-encryption.service.spec.ts: 60
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1019
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1029
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1020
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1016
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1014
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1015
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1011
MEDIUM Use_Of_Hardcoded_Password /libs/common/src/vault/models/domain/cipher.spec.ts: 1012

More results are available on the CxOne platform

@quexten quexten marked this pull request as ready for review September 4, 2025 09:02
@quexten quexten requested review from a team as code owners September 4, 2025 09:02
Copy link

codecov bot commented Sep 4, 2025

Codecov Report

❌ Patch coverage is 48.14815% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.45%. Comparing base (b957a0c) to head (85c623d).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...common/collections/models/collection-admin.view.ts 0.00% 8 Missing ⚠️
...e/src/common/collections/models/collection.view.ts 0.00% 4 Missing ⚠️
libs/common/src/vault/models/domain/folder.ts 50.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16284   +/-   ##
=======================================
  Coverage   37.45%   37.45%           
=======================================
  Files        3352     3352           
  Lines       95228    95248   +20     
  Branches    14395    14395           
=======================================
+ Hits        35668    35679   +11     
- Misses      57987    57996    +9     
  Partials     1573     1573           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

sonarqubecloud bot commented Sep 4, 2025

@quexten quexten changed the title Add error handling stubs & logging for critical decrypt paths [PM-25458] Add error handling stubs & logging for critical decrypt paths Sep 4, 2025
Comment on lines +163 to +166
console.log(
"[CollectionAdminView/fromCollectionResponse] Failed to decrypt the collection name",
e,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
console.log(
"[CollectionAdminView/fromCollectionResponse] Failed to decrypt the collection name",
e,
);
console.error(
"[CollectionAdminView/fromCollectionResponse] Failed to decrypt the collection name",
e,
);

Comment on lines +324 to +327
// Note: This should be replaced by the owning team with appropriate, domain-specific behavior.
// eslint-disable-next-line no-console
console.error("[TokenService] Error decrypting access token", e);
throw e;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Note: This should be replaced by the owning team with appropriate, domain-specific behavior.
// eslint-disable-next-line no-console
console.error("[TokenService] Error decrypting access token", e);
throw e;
// Note: This should be replaced by the owning team with appropriate, domain-specific behavior.
this.logService.error("[TokenService] Error decrypting access token", e);
throw e;

Looks like logService is available here.

@@ -36,10 +36,12 @@ export abstract class EncryptService {
abstract decryptString(encString: EncString, key: SymmetricCryptoKey): Promise<string>;
/**
* Decrypts an EncString to a Uint8Array
* @throws IMPORTANT: This throws if decryption fails. If decryption failures are expected to happen,
* the callsite should log where the failure occurred, and handle it by domain specifc logic (e.g. show a UI error).
*
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Shouldn't this be on decryptString?

} catch (e) {
// eslint-disable-next-line no-console
console.error("[EncString Generic Decrypt] failed to decrypt encstring", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add the context input parameter to the log?

Copy link
Contributor

@gbubemismith gbubemismith left a comment

Choose a reason for hiding this comment

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

Vault changes look good

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.

4 participants