Skip to content

Conversation

@quexten
Copy link
Contributor

@quexten quexten commented Oct 20, 2025

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-27115
https://bitwarden.atlassian.net/browse/VULN-185
https://bitwarden.atlassian.net/browse/PM-4185

📔 Objective

Forces the icon URI check for crypto v2 users. This adds some plumbing through the key store, which now also includes other non-key cryptographic state. The account security version is expected to be used in many other places that have access to the key store and we do not want to pass through an additional struct to all places.

Please see the tickets for context about what specifically this change achieves.

Further, this fixes the icon uri check to be constant time.

⏰ 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

@claude

This comment was marked as resolved.

@quexten quexten changed the title Force icon uri checksum verification on user crypto v2 & make check c… Force icon uri checksum verification on user crypto v2 Oct 20, 2025
@quexten quexten changed the title Force icon uri checksum verification on user crypto v2 [PM-27115] Force icon uri checksum verification on user crypto v2 Oct 20, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 20, 2025

Logo
Checkmarx One – Scan Summary & Details4113a52b-b2ad-48f9-b5fb-bd806c899d9b

Great job! No new security vulnerabilities introduced in this pull request

@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Oct 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.37%. Comparing base (79eb8c4) to head (b50d5b9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #519      +/-   ##
==========================================
+ Coverage   78.36%   78.37%   +0.01%     
==========================================
  Files         291      291              
  Lines       29343    29366      +23     
==========================================
+ Hits        22994    23017      +23     
  Misses       6349     6349              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@quexten quexten marked this pull request as ready for review October 20, 2025 10:55
@quexten quexten requested review from a team as code owners October 20, 2025 10:55
mzieniukbw
mzieniukbw previously approved these changes Oct 23, 2025
// We use an Arc<> to make it easier to pass this store around, as we can
// clone it instead of passing references
inner: Arc<RwLock<KeyStoreInner<Ids>>>,
security_state_version: Arc<RwLock<u64>>,
Copy link
Member

@dani-garcia dani-garcia Oct 27, 2025

Choose a reason for hiding this comment

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

Should this instead be a part of KeyStoreInner to reuse the existing lock?

Having two locks seems wasteful and I feel like could lead to accidental deadlocks. In fact the current code in context_mut() smells like it could cause a deadlock to me, as we get a write lock for the global_keys and then we try to read the security state while holding the lock. If any other part of the codebase read those two in the opposite order, we'd have issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed now

pub fn context(&'_ self) -> KeyStoreContext<'_, Ids> {
let data = self.inner.read().expect("RwLock is poisoned");
KeyStoreContext {
global_keys: GlobalKeys::ReadOnly(self.inner.read().expect("RwLock is poisoned")),
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: You can probably restructure this in the same way of context_mut to avoid calling inner.read() twice. it won't ever deadlock so this isn't a blocking problem, but it's mildly wasteful to do it twice if not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 178fe43

/// Sets the security state version for this store.
pub fn set_security_state_version(&self, version: u64) {
let mut data = self.inner.write().expect("RwLock is poisoned");
data.security_state_version = version;
Copy link
Member

Choose a reason for hiding this comment

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

Non-blocking question: Would we want to add some rollback protection here in the future? Something like:

if version < data.security_state_version {
    return Err(...);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! However, I do think this should be considered when sync and at least the crypto state is managed in SDK.

@quexten quexten requested review from mzieniukbw and removed request for addisonbeck and shane-melton October 29, 2025 10:11
@quexten quexten requested a review from shane-melton October 29, 2025 10:12
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