Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-11941] Migrate TOTP Generator to use SDK #12987

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

gbubemismith
Copy link
Member

🎟️ Tracking

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

📔 Objective

Migrate Totp Generation service to use sdk. This PR depends on bitwarden/sdk-internal#126

📸 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

@gbubemismith gbubemismith requested a review from a team as a code owner January 20, 2025 18:17
@gbubemismith gbubemismith requested a review from Jingo88 January 20, 2025 18:17
Copy link
Contributor

github-actions bot commented Jan 20, 2025

Logo
Checkmarx One – Scan Summary & Detailsfdb7ba19-84f3-41db-8444-cbea37edae1b

New Issues (13)

Checkmarx found the following issues in this Pull Request

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Client_Privacy_Violation /apps/desktop/src/vault/app/vault/view.component.html: 497
detailsMethod view_component at line 497 of /apps/desktop/src/vault/app/vault/view.component.html sends user information outside the application. This may...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/desktop/src/vault/app/vault/view.component.html: 497
detailsMethod view_component at line 497 of /apps/desktop/src/vault/app/vault/view.component.html sends user information outside the application. This may...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/desktop/src/vault/app/vault/view.component.html: 497
detailsMethod view_component at line 497 of /apps/desktop/src/vault/app/vault/view.component.html sends user information outside the application. This may...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/desktop/src/vault/app/vault/view.component.html: 470
detailsMethod view_component at line 470 of /apps/desktop/src/vault/app/vault/view.component.html sends user information outside the application. This may...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/desktop/src/vault/app/vault/view.component.html: 470
detailsMethod view_component at line 470 of /apps/desktop/src/vault/app/vault/view.component.html sends user information outside the application. This may...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/desktop/src/vault/app/vault/view.component.html: 470
detailsMethod view_component at line 470 of /apps/desktop/src/vault/app/vault/view.component.html sends user information outside the application. This may...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/web/src/app/vault/individual-vault/view.component.ts: 80
detailsMethod at line 80 of /apps/web/src/app/vault/individual-vault/view.component.ts sends user information outside the application. This may constitut...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/web/src/app/vault/individual-vault/view.component.ts: 80
detailsMethod at line 80 of /apps/web/src/app/vault/individual-vault/view.component.ts sends user information outside the application. This may constitut...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/web/src/app/vault/individual-vault/view.component.ts: 80
detailsMethod at line 80 of /apps/web/src/app/vault/individual-vault/view.component.ts sends user information outside the application. This may constitut...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/web/src/app/vault/individual-vault/view.component.ts: 106
detailsMethod ngOnInit at line 106 of /apps/web/src/app/vault/individual-vault/view.component.ts sends user information outside the application. This may ...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/web/src/app/vault/individual-vault/view.component.ts: 106
detailsMethod ngOnInit at line 106 of /apps/web/src/app/vault/individual-vault/view.component.ts sends user information outside the application. This may ...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/web/src/app/vault/individual-vault/view.component.ts: 106
detailsMethod ngOnInit at line 106 of /apps/web/src/app/vault/individual-vault/view.component.ts sends user information outside the application. This may ...
Attack Vector
MEDIUM Client_Privacy_Violation /apps/browser/src/autofill/background/overlay.background.ts: 696
detailsMethod buildCipherData at line 696 of /apps/browser/src/autofill/background/overlay.background.ts sends user information outside the application. T...
Attack Vector
Fixed Issues (4)

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

Severity Issue Source File / Package
MEDIUM Client_Privacy_Violation /apps/browser/src/autofill/background/overlay.background.ts: 695
MEDIUM Client_Privacy_Violation /apps/browser/src/autofill/background/overlay.background.ts: 696
MEDIUM Client_Privacy_Violation /libs/vault/src/components/totp-countdown/totp-countdown.component.ts: 17
MEDIUM Client_Privacy_Violation /libs/vault/src/components/totp-countdown/totp-countdown.component.ts: 16

@gbubemismith gbubemismith marked this pull request as draft January 21, 2025 19:40
@gbubemismith gbubemismith marked this pull request as ready for review January 22, 2025 15:10
@gbubemismith gbubemismith requested a review from a team as a code owner January 22, 2025 15:10
@gbubemismith gbubemismith requested a review from Hinton January 23, 2025 17:52
Copy link
Contributor

@coroiu coroiu left a comment

Choose a reason for hiding this comment

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

I think this PR is good for approval but you'll need to merge the SDK PR first and then update package.json in this PR to point to pull in the new TOTP functionality. Re-request a review from me then and I'll approve this PR 👍

/**
* Represents TOTP information including display formatting and timing
*/
export type TotpInfo = {
Copy link
Contributor

Choose a reason for hiding this comment

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

question(non-blocking): are we defining the type here but not using it here? It seems the implementation for mapping TotpResponse to TotpInfo is in view.component.ts?

Copy link
Member Author

Choose a reason for hiding this comment

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

totp-countdown.component.ts also uses it

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

Attention: Patch coverage is 27.11864% with 43 lines in your changes missing coverage. Please review.

Project coverage is 35.17%. Comparing base (543cf0f) to head (0a0a85d).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ponents/totp-countdown/totp-countdown.component.ts 9.09% 10 Missing ⚠️
...c/app/vault/individual-vault/add-edit.component.ts 0.00% 7 Missing ⚠️
...ibs/angular/src/vault/components/view.component.ts 0.00% 6 Missing ⚠️
...wser/src/autofill/background/overlay.background.ts 28.57% 1 Missing and 4 partials ⚠️
...pps/desktop/src/vault/app/vault/vault.component.ts 0.00% 4 Missing ⚠️
apps/cli/src/commands/get.command.ts 0.00% 3 Missing ⚠️
.../src/app/vault/individual-vault/vault.component.ts 0.00% 2 Missing ⚠️
...pps/web/src/app/vault/org-vault/vault.component.ts 0.00% 2 Missing ⚠️
...bs/vault/src/services/copy-cipher-field.service.ts 50.00% 1 Missing and 1 partial ⚠️
apps/browser/src/background/main.background.ts 0.00% 1 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12987      +/-   ##
==========================================
- Coverage   35.20%   35.17%   -0.03%     
==========================================
  Files        3126     3126              
  Lines       92563    92456     -107     
  Branches    16857    16831      -26     
==========================================
- Hits        32590    32526      -64     
+ Misses      57516    57478      -38     
+ Partials     2457     2452       -5     

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

coroiu
coroiu previously approved these changes Jan 31, 2025
Copy link
Contributor

@coroiu coroiu left a comment

Choose a reason for hiding this comment

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

LGTM 👍

await this.totpService.getCode(cipher.login.totp),
);
const totpResponse = await firstValueFrom(this.totpService.getCode$(cipher.login.totp));
this.platformUtilsService.copyToClipboard(totpResponse.code);
Copy link
Contributor

@jprusik jprusik Feb 4, 2025

Choose a reason for hiding this comment

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

Is totpResponse guaranteed to have a code property in this scenario (and elsewhere)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is a similar question to this #12987 (comment), it is not guaranteed. How would you prefer errors in this scenario to be handled in the autofill context?

Copy link
Contributor

@jprusik jprusik Feb 5, 2025

Choose a reason for hiding this comment

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

Naively, I'd probably do something like

const totpResponse = await firstValueFrom(this.totpService.getCode$(cipher.login.totp));

if (totpResponse?.code) {
  this.platformUtilsService.copyToClipboard();
} else {
  /* 
  let the user know the copy didn't happen in whatever way 
  makes sense for the context (toast, console error, etc)
  */
}

Comment on lines 975 to 977
let totpValue = (
await firstValueFrom(this.totpService.getCode$(options.cipher.login.totp))
).code;
Copy link
Contributor

Choose a reason for hiding this comment

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

readability nit:

Suggested change
let totpValue = (
await firstValueFrom(this.totpService.getCode$(options.cipher.login.totp))
).code;
const totpResponse = await firstValueFrom(
this.totpService.getCode$(options.cipher.login.totp),
);
let totpValue = totpResponse.code;

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks

jprusik
jprusik previously approved these changes Feb 4, 2025
Copy link
Contributor

@jprusik jprusik left a comment

Choose a reason for hiding this comment

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

One small question, otherwise LGTM for Autofill concerns

@gbubemismith gbubemismith dismissed stale reviews from jprusik and coroiu via afebd07 February 5, 2025 17:05
jprusik
jprusik previously approved these changes Feb 5, 2025
@gbubemismith gbubemismith requested a review from coroiu February 6, 2025 15:07
coroiu
coroiu previously approved these changes Feb 7, 2025
@gbubemismith gbubemismith dismissed stale reviews from coroiu and jprusik via 0a0a85d February 10, 2025 22:04
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