Skip to content

[PM-34909] Serve only validated report files from get-latest and self-hosted file endpoints#7465

Draft
AlexRubik wants to merge 138 commits intomainfrom
dirt/pm-34909/serve-validated-report-files
Draft

[PM-34909] Serve only validated report files from get-latest and self-hosted file endpoints#7465
AlexRubik wants to merge 138 commits intomainfrom
dirt/pm-34909/serve-validated-report-files

Conversation

@AlexRubik
Copy link
Copy Markdown
Contributor

@AlexRubik AlexRubik commented Apr 14, 2026

Note: This branch was created on top of #7228 (PM-31923), so the diff currently includes all of #7228's changes. Once #7228 merges into main, this PR's diff will shrink to just the PM-34909 changes.

🎟️ Tracking

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

📔 Objective

Closes three correctness gaps left by #7228 in the Access Intelligence report file storage endpoints, gated behind pm-31920-access-intelligence-azure-file-storage:

  1. GetLatest endpoint: Add @FilterByValidated parameter to the OrganizationReport_GetLatestByOrganizationId stored procedure. When the flag is ON, the controller passes filterByValidated=true through the query and repository layers so only reports with validated files are returned.
  2. Download endpoint (self-hosted): When the flag is ON, reject requests for reports whose files have not been validated.
  3. Upload endpoint (self-hosted): Add re-upload guard (|| fileData.Validated) to prevent overwriting an already-validated file, matching the existing pattern in RenewFileUploadUrlAsync.

When the flag is OFF, all three endpoints behave exactly as they do today.

📸 Screenshots

Not applicable -- no UI changes.

prograhamming and others added 30 commits February 25, 2026 08:44
…elligence' of github.com:bitwarden/server into dirt/PM-31923-whole-report-data-v2-endpoints-access-intelligence
…elligence' of github.com:bitwarden/server into dirt/PM-31923-whole-report-data-v2-endpoints-access-intelligence
* refactor(billing): update seat logic

* test(billing): update tests for seat logic
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* Return WebAuthn credential record in create response

* Make CreateWebAuthnLoginCredentialCommand null-safe
…#7123)

* Remove emergency access from all organization users on policy enable, or when accepted/restored

* Use correct policy save system

* Add additional tests

* Implement both PreUpsert and OnSave side effects
* Add coupon support to invoice preview and subscription creation

* Fix the build lint error

* Resolve the initial review comments

* fix  the failing test

* fix the build lint error

* Fix the failing test

* Resolve the unaddressed issues

* Fixed the deconstruction error

* Fix the lint issue

* Fix the lint error

* Fix the lint error

* Fix the build lint error

* lint error resolved

* remove the setting file

* rename the variable name  validatedCoupon

* Remove the owner property

* Update OrganizationBillingService tests to align with recent refactoring

- Remove GetMetadata tests as method no longer exists
- Remove Owner property references from OrganizationSale (removed in d761336)
- Update coupon validation to use SubscriptionDiscountRepository instead of SubscriptionDiscountService
- Add missing imports for SubscriptionDiscount entities
- Rename test for clarity: Finalize_WithNullOwner_SkipsValidation → Finalize_WithCouponOutsideDateRange_IgnoresCouponAndProceeds

All tests passing (14/14)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix the lint error

* Making the owner non nullable

* fix the failing unit test

* Make the owner nullable

* Fix the bug for coupon in Stripe with no audience restrictions(PM-32756)

* Return validation message for invalid coupon

* Update the valid token message

* Fix the failing unit test

* Remove the duplicate method

* Fix the failing build and test

* Resolve the failing test

* Add delete of invalid coupon

* Add the expired error message

* Delete on invalid coupon in stripe

* Fix the lint errors

* return null if we get exception from stripe

* remove the auto-delete change

* fix the failing test

* Fix the lint build error

---------

Co-authored-by: Claude <noreply@anthropic.com>
feat: add MasterPasswordSalt column to User table

- Add MasterPasswordSalt column to User table in both Dapper and EF implementations
- Update User stored procedures (Create, Update, UpdateMasterPassword) to handle salt column
- Add EF migrations and update UserView with dependent views
- Set MaxLength constraint on MasterPasswordSalt column
- Update UserRepository implementations to manage salt field
- Add comprehensive test coverage for salt handling and normalization
…elligence' of github.com:bitwarden/server into dirt/PM-31923-whole-report-data-v2-endpoints-access-intelligence
prograhamming and others added 27 commits March 23, 2026 10:47
Add @FilterByValidated parameter to OrganizationReport_GetLatestByOrganizationId.
When set, uses JSON_VALUE to return only reports with validated files.
Defaults to 0 for backwards compatibility.

Includes migration script for deployment.

[PM-34909]
Thread filterByValidated parameter through IOrganizationReportRepository,
Dapper (passes to SP), and EF (string.Contains LINQ filter) implementations.
Defaults to false for backwards compatibility.

[PM-34909]
Pass the validated filter parameter from the controller through
the query interface to the repository layer.

[PM-34909]
- GetLatest: pass filterByValidated to query when flag is ON,
  ensuring only validated reports are returned
- Download: reject unvalidated files when flag is ON
- Upload: reject re-upload if file is already validated

[PM-34909]
- Update existing GetLatest mock to pass filterByValidated=true
- Add GetLatest filter parameter tests (flag ON/OFF)
- Add download validation guard tests (flag ON validated/unvalidated, flag OFF)
- Add upload re-upload guard test
- Add query layer parameter threading tests

[PM-34909]
The pre-commit hook incorrectly stripped required usings from files
it touched (Dapper, SqlConnection, AutoMapper, LinqToDB, xUnit, NSubstitute).
These imports are used by other methods in the same files.

[PM-34909]
- Upload test: set up DefaultHttpContext with multipart content type
  to reach the validated file guard past the content type check
- Flag-OFF test: clear ReportFile to avoid JSON deserialization error
  from AutoFixture-generated random string
- Add Microsoft.AspNetCore.Http import for DefaultHttpContext

[PM-34909]
@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 77.94317% with 163 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.22%. Comparing base (f6e858b) to head (efa1321).
⚠️ Report is 44 commits behind head on main.

Files with missing lines Patch % Lines
.../Dirt/Controllers/OrganizationReportsController.cs 69.23% 64 Missing and 8 partials ⚠️
.../Services/AzureOrganizationReportStorageService.cs 36.14% 52 Missing and 1 partial ⚠️
.../Services/LocalOrganizationReportStorageService.cs 83.82% 10 Missing and 1 partial ⚠️
.../Dirt/Repositories/OrganizationReportRepository.cs 0.00% 8 Missing ⚠️
...SharedWeb/Utilities/ServiceCollectionExtensions.cs 27.27% 6 Missing and 2 partials ⚠️
...s/Services/NoopOrganizationReportStorageService.cs 0.00% 7 Missing ⚠️
...rts/ReportFeatures/AddOrganizationReportCommand.cs 0.00% 0 Missing and 1 partial ⚠️
.../ReportFeatures/CreateOrganizationReportCommand.cs 98.68% 0 Missing and 1 partial ⚠️
...ports/ReportFeatures/GetOrganizationReportQuery.cs 85.71% 1 Missing ⚠️
...ucture.Dapper/Dirt/OrganizationReportRepository.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7465      +/-   ##
==========================================
+ Coverage   58.49%   63.22%   +4.72%     
==========================================
  Files        2063     2076      +13     
  Lines       91190    91527     +337     
  Branches     8130     8129       -1     
==========================================
+ Hits        53342    57866    +4524     
+ Misses      35949    31658    -4291     
- Partials     1899     2003     +104     

☔ 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.

@github-actions
Copy link
Copy Markdown
Contributor

Logo
Checkmarx One – Scan Summary & Details1696c481-adca-4107-8d53-0d086eb22b1c


New Issues (9) Checkmarx found the following issues in this Pull Request
# Severity Issue Source File / Package Checkmarx Insight
1 MEDIUM CSRF /src/Api/Dirt/Controllers/OrganizationReportsController.cs: 540
detailsMethod at line 540 of /src/Api/Dirt/Controllers/OrganizationReportsController.cs gets a parameter from a user request from reportId. This parame...
Attack Vector
2 MEDIUM CSRF /src/Api/Dirt/Controllers/OrganizationReportsController.cs: 575
detailsMethod at line 575 of /src/Api/Dirt/Controllers/OrganizationReportsController.cs gets a parameter from a user request from organizationId. This ...
Attack Vector
3 MEDIUM CSRF /src/Api/Dirt/Controllers/OrganizationReportsController.cs: 541
detailsMethod at line 541 of /src/Api/Dirt/Controllers/OrganizationReportsController.cs gets a parameter from a user request from request. This paramet...
Attack Vector
4 MEDIUM CSRF /src/Api/Dirt/Controllers/OrganizationReportsController.cs: 539
detailsMethod at line 539 of /src/Api/Dirt/Controllers/OrganizationReportsController.cs gets a parameter from a user request from organizationId. This ...
Attack Vector
5 MEDIUM CSRF /src/Api/Dirt/Controllers/OrganizationReportsController.cs: 541
detailsMethod at line 541 of /src/Api/Dirt/Controllers/OrganizationReportsController.cs gets a parameter from a user request from request. This paramet...
Attack Vector
6 MEDIUM CSRF /src/Api/Dirt/Controllers/OrganizationReportsController.cs: 576
detailsMethod at line 576 of /src/Api/Dirt/Controllers/OrganizationReportsController.cs gets a parameter from a user request from reportId. This parame...
Attack Vector
7 MEDIUM CSRF /src/Api/Dirt/Controllers/OrganizationReportsController.cs: 540
detailsMethod at line 540 of /src/Api/Dirt/Controllers/OrganizationReportsController.cs gets a parameter from a user request from reportId. This parame...
Attack Vector
8 MEDIUM CSRF /src/Api/Dirt/Controllers/OrganizationReportsController.cs: 577
detailsMethod at line 577 of /src/Api/Dirt/Controllers/OrganizationReportsController.cs gets a parameter from a user request from request. This paramet...
Attack Vector
9 MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 289
detailsMethod at line 289 of /src/Api/AdminConsole/Controllers/GroupsController.cs gets a parameter from a user request from orgUserId. This parameter ...
Attack Vector

Fixed Issues (5) Great job! The following issues were fixed in this Pull Request
Severity Issue Source File / Package
MEDIUM CSRF /src/Api/AdminConsole/Controllers/GroupsController.cs: 275
MEDIUM CSRF /src/Api/Dirt/Controllers/OrganizationReportsController.cs: 187
MEDIUM CSRF /src/Api/Dirt/Controllers/OrganizationReportsController.cs: 231
MEDIUM CSRF /src/Api/Dirt/Controllers/OrganizationReportsController.cs: 284
MEDIUM CSRF /src/Api/Dirt/Controllers/OrganizationReportsController.cs: 187

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.