Skip to content

[PM-35948] Update send openapi to work for sdk#7556

Open
adudek-bw wants to merge 15 commits intomainfrom
update-send-openapi-to-work-for-sdk
Open

[PM-35948] Update send openapi to work for sdk#7556
adudek-bw wants to merge 15 commits intomainfrom
update-send-openapi-to-work-for-sdk

Conversation

@adudek-bw
Copy link
Copy Markdown
Contributor

@adudek-bw adudek-bw commented Apr 27, 2026

🎟️ Tracking

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

📔 Objective

Update the functions to have actual return values instead of void returns

Update the endpoints to properly handle the different auth types needed

SDK changes: bitwarden/sdk-internal#961

📸 Screenshots

@adudek-bw adudek-bw requested a review from a team as a code owner April 27, 2026 21:53
@adudek-bw adudek-bw requested review from coroiu and harr1424 April 27, 2026 21:53
Comment thread src/Api/Tools/Controllers/SendsController.cs
@coroiu coroiu added ai-review Request a Claude code review and removed ai-review Request a Claude code review labels Apr 28, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

Logo
Checkmarx One – Scan Summary & Detailsaaae51fa-c5b5-4c1b-ade5-3ad01c8163cc


New Issues (4) Checkmarx found the following issues in this Pull Request
# Severity Issue Source File / Package Checkmarx Insight
1 MEDIUM CSRF src/Api/Tools/Controllers/SendsController.cs: 77
detailsMethod at line 77 of /src/Api/Tools/Controllers/SendsController.cs gets a parameter from a user request from id. This parameter value flows thro...
Attack Vector
2 MEDIUM CSRF src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 514
detailsMethod at line 514 of /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs gets a parameter from a user request from model. This par...
Attack Vector
3 MEDIUM CSRF src/Api/Vault/Controllers/CiphersController.cs: 1558
detailsMethod at line 1558 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
Attack Vector
4 MEDIUM CSRF src/Api/Vault/Controllers/CiphersController.cs: 1385
detailsMethod at line 1385 of /src/Api/Vault/Controllers/CiphersController.cs gets a parameter from a user request from id. This parameter value flows ...
Attack Vector

Fixed Issues (2) Great job! The following issues were fixed in this Pull Request
Severity Issue Source File / Package
MEDIUM CSRF src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 512
MEDIUM CSRF src/Api/Tools/Controllers/SendsController.cs: 73

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

❌ Patch coverage is 29.50820% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.71%. Comparing base (d9149c0) to head (242f07e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...aredWeb/Swagger/SendAccessBearerOperationFilter.cs 0.00% 27 Missing ⚠️
src/Api/Startup.cs 0.00% 14 Missing ⚠️
src/Api/Tools/Controllers/SendsController.cs 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7556      +/-   ##
==========================================
- Coverage   59.73%   59.71%   -0.02%     
==========================================
  Files        2109     2110       +1     
  Lines       92752    92809      +57     
  Branches     8246     8251       +5     
==========================================
+ Hits        55402    55421      +19     
- Misses      35385    35424      +39     
+ Partials     1965     1964       -1     

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

@harr1424 harr1424 self-requested a review April 28, 2026 21:29
harr1424
harr1424 previously approved these changes Apr 28, 2026
if (sendAuthResult.Equals(SendAccessResult.PasswordRequired))
{
return new UnauthorizedResult();
throw new UnauthorizedAccessException();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion(non-blocking): Align

return new UnauthorizedResult();
to also throw for consistency (they return different response bodies)

suggestion(non-blocking): Tests don't check this unhappy path, consider adding new ones

Comment thread src/Api/Tools/Controllers/SendsController.cs

[AllowAnonymous]
[HttpPost("{encodedSendId}/access/file/{fileId}")]
[ProducesResponseType<SendFileDownloadDataResponseModel>(StatusCodes.Status200OK)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: any reason this endpoint kept Task<IActionResult> + the explicit 200 annotation, instead of being refactored to Task<SendFileDownloadDataResponseModel> like Access? The only thing blocking that is the UnauthorizedResult return — same throw switch as Access would unify the two.

Copy link
Copy Markdown
Contributor

@itsadrago itsadrago May 8, 2026

Choose a reason for hiding this comment

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

@adudek-bw, in addition to GetSendFileDownloadDataUsingAuth (as pointed out above), there is another action (AccessUsingAuth) that's still returning IActionResult. We should make sure we address returning the correct response model for all the actions in the controller

/// the OpenAPI generator to emit an explicit Bearer token parameter rather than injecting the
/// user session token via middleware.
/// </summary>
public class SendAccessBearerOperationFilter : IOperationFilter
Copy link
Copy Markdown
Contributor

@coroiu coroiu Apr 29, 2026

Choose a reason for hiding this comment

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

question/issue: Have you generated the bindings to confirm this fix works?

From what I can see using Claude the V2 operations don' get the send-access-bearer security in the generated api.json. Verified by running pwsh dev/generate_openapi_files.ps1 on this branch, the V2 operations have security: [{}] (empty requirement object, equivalent to "no auth required") instead of the expected security: [{"send-access-bearer": []}].

According to Claude the cause is that new OpenApiSecuritySchemeReference("send-access-bearer") is constructed without the host document, so the reference doesn't serialize as a $ref. Fix: convert the filter to IDocumentFilter (which receives the document) and pass it to the reference constructor — same pattern as AddSwaggerServerWithSecurity in SharedWeb/Utilities/ServiceCollectionExtensions.cs:867-870.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the info on the command! I updated the code :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: Is V1 out of scope? Same IDocumentFilter could potentially also override [AllowAnonymous] endpoints in SendsController to security: [], which could let the SDK drop hand-rolled V1 calls

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 8, 2026

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