Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[BEEEP] [PM-28808] Fix invalid identity URL in Swagger#6653

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
eliykat wants to merge12 commits intomain
base:main
Choose a base branch
Loading
fromac/pm-28808/swagger-download-has-invalid-identity-tokenurl

Conversation

@eliykat
Copy link
Member

@eliykateliykat commentedNov 27, 2025
edited
Loading

🎟️ Tracking

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

📔 Objective

We have a swagger.json and SwaggerUI hosted on our Help Center for the public API:https://bitwarden.com/help/api/.

However it currently has the following issues:

  • only supports targeting the US server - not EU
  • the identity endpoint is set tolocalhost - so the Authorize button doesn't work and you can't use the "Try it out" functionality

This PR makes the following changes:

  • in SwaggerGen configuration - configure US and EU servers and corresponding authorization options. This is the default configuration that will be used to produce theswagger.json build artifact, which is used by the Help Center.
    • note: you cannot automatically associate the server with the authorization option (or otherwise parameterize it etc) so the best we can do is try to clearly explain which authorization to use
    • this should be permitted by CORS because our cloud servers permit requests from the product website:ref.
  • in the API project Swagger configuration - override the default config with the details of the locally running server. This will be used for development servers and self-host servers.

We used to specify the--host option ingenerate_openapi_files.ps1 but that is no longer needed (and in any case didn't work because you can't specify the authorization config from the command line).

I think this approach is reasonable but I am open to other ways to achieve this. Platform should probably be the one to review this.

📸 Screenshots

Preview of how it should look on the Help Center:

Screen.Recording.2025-11-27.at.1.03.51.pm.mov

Preview of how it should look in dev and self hosted:

Screen.Recording.2025-11-27.at.1.06.04.pm.mov

⏰ 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

- in generated JSON (used in help center), only show cloud options- in self-host and dev, only show local optionMixing these will cause CORS issues because server is not expectingrequests from those origins.
@claude
Copy link
Contributor

claudebot commentedNov 27, 2025
edited
Loading

Claude finished@eliykat's task ——View job


Code Review Complete

I've reviewed the changes to fix the invalid identity URL in Swagger. The implementation is solid and addresses the stated problem. Here are my findings:


Summary

This PR successfully configures Swagger to support both US and EU cloud servers in the generatedswagger.json artifact for the Help Center, while dynamically overriding to local configuration for development and self-hosted environments. The approach elegantly balances the needs of different deployment scenarios.


Findings

Finding 1: Missing unit tests for new extension method (⚠️)

The newAddSwaggerServerWithSecurity extension method insrc/SharedWeb/Utilities/ServiceCollectionExtensions.cs:1081-1128 lacks test coverage, which contributes to the 35 missing lines reported by Codecov. While Swagger configuration is challenging to test, the method contains non-trivial logic (URI parsing, dictionary construction, OpenAPI object creation) that would benefit from verification.

Suggested test approach

Create a test classSharedWeb.Test/Utilities/ServiceCollectionExtensionsTests.cs that:

  • Verifies servers are added with correct URLs and descriptions
  • Confirms security definitions are created with proper token URLs
  • Validates security requirements reference the correct scheme IDs
  • Checks that multiple calls add multiple server configurations

Reference the existingSwaggerDocUtil.cs test utility for SwaggerGen setup patterns.

Finding 2: Codecov reports 35 lines missing coverage in Startup.cs (💭)

The PreSerializeFilters code insrc/Api/Startup.cs:304-344 shows as untested. This is expected since:

  • This code only runs in Development/SelfHosted environments
  • The filters execute at runtime when serving swagger.json
  • The CI pipeline generates swagger artifacts using Development environment but doesn't exercise the filter execution path

Consider whether integration tests that actually fetch the swagger.json endpoint would be valuable, though this may be excessive for configuration code.

Finding 3: Potential confusion between security schemes for end users (💭)

With multiple servers (US/EU) and multiple security definitions (US_server/EU_server), users must manually match the server selection with the correct authorization option. The PR description acknowledges this limitation with the note: "you cannot automatically associate the server with the authorization option."

The added description text helps ("Use this option if you've selected the {serverDescription}" and "Note: your authorization must match the server you have selected"), but users could still select US server + EU authorization.

This appears to be a limitation of OpenAPI/Swagger UI rather than the implementation. The current approach with clear descriptions is reasonable given the constraints.

Finding 4: Security scheme clearing in PreSerializeFilters is correct (👍)

TheswaggerDoc.Components.SecuritySchemes.Clear() andswaggerDoc.SecurityRequirements.Clear() insrc/Api/Startup.cs:312,329 properly remove cloud server configurations for local environments, ensuring development/self-hosted deployments don't expose cloud identity URLs.


Security Considerations

✅ No security issues identified. The changes:

  • Don't expose sensitive data
  • Correctly configure OAuth2 endpoints for different environments
  • Properly isolate cloud vs. local configurations
  • Are read-only documentation changes that don't affect authentication logic

Response to Previous Review Feedback

The author (eliykat) correctly explained why dani-garcia's simplification suggestion wouldn't work: the CI pipeline uses Development environment for swagger generation but needs to output cloud server configurations. The PreSerializeFilters approach is the correct solution to override configuration based on runtime environment.


Code Quality Observations

✅ Method naming:AddSwaggerAddSwaggerGen better reflects that it configures SwaggerGen
✅ Documentation: XML comments and inline comments clearly explain the dual-configuration strategy
✅ Separation of concerns: Extension method in SharedWeb makes it reusable
✅ Code organization: Clear comments distinguish cloud vs. local configuration sections


Recommendations

  1. Add unit tests forAddSwaggerServerWithSecurity to improve coverage and prevent regressions (⚠️ priority)
  2. Consider documenting the server/auth matching requirement in Help Center docs when this is deployed
  3. The codecov coverage drop is acceptable given the nature of the code (runtime filters in development-only paths)

Action Items for Author

  • Add unit tests forAddSwaggerServerWithSecurity extension method
  • (Optional) Coordinate with docs team about server/authorization matching guidance

Overall this is a well-implemented solution that properly addresses the issue within the constraints of the Swagger/OpenAPI specification. The approach of configuring cloud servers by default and overriding for local environments is sound.

@eliykateliykat requested review froma team anddjsmith85November 27, 2025 02:49
@github-actions
Copy link
Contributor

github-actionsbot commentedNov 27, 2025
edited
Loading

Logo
Checkmarx One – Scan Summary & Detailsf4b9c54c-4639-4e3d-839c-90370bcd0991

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

@eliykateliykat changed the title[BEEEP] [PM-28808] Swagger has invalid identity URL[BEEEP] [PM-28808] Fix invalid identity URL in SwaggerNov 27, 2025
@codecov
Copy link

codecovbot commentedNov 27, 2025
edited
Loading

Codecov Report

❌ Patch coverage is62.76596% with35 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.25%. Comparing base (f151abe) to head (da83f52).

Files with missing linesPatch %Lines
src/Api/Startup.cs14.63%35 Missing⚠️
Additional details and impacted files
@@           Coverage Diff           @@##             main    #6653   +/-   ##=======================================  Coverage   53.25%   53.25%           =======================================  Files        1906     1906             Lines       84952    85013   +61       Branches     7635     7635           =======================================+ Hits        45244    45277   +33- Misses      37954    37982   +28  Partials     1754     1754

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

dani-garcia
dani-garcia previously approved these changesNov 27, 2025
Copy link
Member

@dani-garciadani-garcia left a comment

Choose a reason for hiding this comment

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

Looks good to me, can confirm that the generated schemas work and match what's expected. I've also checked that the SDK works when the schema has multiple servers defined and besides some code duplication that I fixed inbitwarden/sdk-internal#589, everything works great.

I've left a non-blocking suggestion on a possible way to remove the manual modification of the servers list, I've tested it locally and it seems to do the trick but I may have missed some corner case.

// Configure Bitwarden cloud US and EU servers. These will appear in the swagger.json build artifact
// used for our help center. These are overwritten with the local server when running in self-hosted
// or dev mode (see Api Startup.cs).
config.AddSwaggerServerWithSecurity(
Copy link
Member

@dani-garciadani-garciaNov 27, 2025
edited
Loading

Choose a reason for hiding this comment

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

I wonder if it wouldn't be easier to change this code to be:

if(globalSettings.SelfHosted){// Configure self-hosted serverconfig.AddSwaggerServerWithSecurity(serverId:"self_hosted_server",serverUrl:globalSettings.BaseServiceUri.Api,identityTokenUrl:$"{globalSettings.BaseServiceUri.Identity}/connect/token",serverDescription:"Self-hosted");}else{// Configure Bitwarden cloud US and EU servers. These will appear in the swagger.json build artifact// used for our help center. These are overwritten with the local server when running in self-hosted// or dev mode (see Api Startup.cs).config.AddSwaggerServerWithSecurity(serverId:"US_server",serverUrl:"https://api.bitwarden.com",identityTokenUrl:"https://identity.bitwarden.com/connect/token",serverDescription:"US server");config.AddSwaggerServerWithSecurity(serverId:"EU_server",serverUrl:"https://api.bitwarden.eu",identityTokenUrl:"https://identity.bitwarden.eu/connect/token",serverDescription:"EU server");}

And then remove the manual modification of the servers that is currently being done usingconfig.PreSerializeFilters inStartup.Cs. Seems to generate the same servers in the schema when run locally.

dani-garcia added a commit to bitwarden/sdk-internal that referenced this pull requestNov 27, 2025
## 🎟️ Tracking<!-- Paste the link to the Jira or GitHub issue or otherwise describe /point to where this change is coming from. -->## 📔 ObjectiveThe server bindings template iterates over all auth methods of all theservers and generates code for each of them. This means that if theschema has two servers defined (like the US and EU servers) it willgenerate code like this:```rust        if let Some(ref token) = config.oauth_access_token {            request = request.bearer_auth(token.to_owned());        };        // This one is just duplicate        if let Some(ref token) = config.oauth_access_token {            request = request.bearer_auth(token.to_owned());        };```This won't break anything and is safe to do, but it's kind of wasteful.Instead, we can just use the first auth method only.The change doesn't have any effect on the bindings for the moment aswe're only ever defining one server and one auth method, butbitwarden/server#6653 will add the US and EUservers to the server API schema, which will result in the above shownduplication.## 🚨 Breaking Changes<!-- Does this PR introduce any breaking changes? If so, please describethe impact and migration path for clients.If you're unsure, the automated TypeScript compatibility check will runwhen you open/update this PR and provide feedback.For breaking changes:1. Describe what changed in the client interface2. Explain why the change was necessary3. Provide migration steps for client developers4. Link to any paired client PRs if neededOtherwise, you can remove this section. -->## ⏰ 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) orinformed the documentation  team## 🦮 Reviewer guidelines<!-- Suggested interactions but feel free to use (or not) as you desire!-->- 👍 (`:+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 inquirythat's not quite a confirmed  issue and could potentially benefit from discussion- 🎨 (`:art:`) for suggestions / improvements- ❌ (`:x:`) or⚠️ (`:warning:`) for more significant problems orconcerns needing attention- 🌱 (`:seedling:`) or ♻️ (`:recycle:`) for future improvements orindications of technical debt- ⛏ (`:pick:`) for minor or nitpick changes
@eliykat
Copy link
MemberAuthor

eliykat commentedNov 28, 2025
edited
Loading

Thanks@dani-garcia ! I did mean to ask about how this would affect the SDK so thank you for checking that.

I tried your suggestion, but the pipeline generates the swagger jsons using thedevelopment environment configuration which means it outputs thelocalhost configuration. If I change that to using Production, it fails because no server certificates are configured; using the Development environment seems like a way to bypass the configuration required for a real server. Maybe that in itself needs to be revisited (do we need a CI environment type? not sure) but I thought that was out of scope for this PR.

@eliykateliykat requested review fromdani-garcia and removed request forjustindbaurNovember 28, 2025 01:13
@eliykateliykatenabled auto-merge (squash)November 28, 2025 22:00
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@dani-garciadani-garciadani-garcia approved these changes

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@eliykat@dani-garcia

[8]ページ先頭

©2009-2025 Movatter.jp