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

[AC-2933] [Fix] Support for bitwarden.eu cloud #57

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

Conversation

jpclipffel
Copy link

🎟️ Tracking

#56

📔 Objective

Support for non-US cloud instances (e.g. bitwarden.eu).

Details:

  • Parse serverUrl as an URL
  • Use serverUrl.host as host value
  • Support bitwarden.com and bitwarden.eu as cloud instances

⏰ 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

- Parse `serverUrl` as an `URL`
- Use `serverUrl.host` as host value
- Support `bitwarden.com` and `bitwarden.eu` as cloud instances
@jpclipffel jpclipffel requested a review from a team as a code owner July 22, 2024 12:04
@jpclipffel jpclipffel requested a review from addisonbeck July 22, 2024 12:04
@djsmith85 djsmith85 linked an issue Jul 22, 2024 that may be closed by this pull request
Copy link

Logo
Checkmarx One – Scan Summary & Details16fd183f-4aee-4636-a2a2-728f683fce3d

No New Or Fixed Issues Found

@addisonbeck
Copy link
Contributor

Thanks for the contribution! This seems straight forward to me. I'm passing it over to our QA team and we'll get it merged once that has passed.

@addisonbeck
Copy link
Contributor

Internal tracking link: https://bitwarden.atlassian.net/browse/AC-2933

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

@mzieniukbw mzieniukbw left a comment

Choose a reason for hiding this comment

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

Thank you @jpclipffel for this addition!
I have raised few issues with your change, please have a look.

Comment on lines +66 to +67
const apiUrl = isBitwardenCloud ? `https://api.${serverUrl.host}` : serverUrl + "/api/";
const identityUrl = isBitwardenCloud ? `https://identity.${serverUrl.host}` : serverUrl + "/identity/";
Copy link
Contributor

@mzieniukbw mzieniukbw Sep 22, 2024

Choose a reason for hiding this comment

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

A pathname for self-hosted server url is optional.
This might result in double forward slash character //, example server url https://HOST would result in https://HOST//api, which python app does not normalize and is technically different href (i.e. https://api.bitwarden.com/public/events works but https://api.bitwarden.com//public/events return 404)
This happens because serverUrl is URL type, which concatenated always have the forward slash character / at the beginning.
For record, this was wrong before, since we did not normalize the paths, but now it's even worse when pathname is not provided.
A quick fix would be to change the serverUrl back to rawServerUrl, but i think proper fix would be to:

Suggested change
const apiUrl = isBitwardenCloud ? `https://api.${serverUrl.host}` : serverUrl + "/api/";
const identityUrl = isBitwardenCloud ? `https://identity.${serverUrl.host}` : serverUrl + "/identity/";
const selfHostedServerUrl = serverUrl.origin + (serverUrl.pathname === "/" ? '' : serverUrl.pathname);
const apiUrl = isBitwardenCloud ? `https://api.${serverUrl.host}` : selfHostedServerUrl + "/api/";
const identityUrl = isBitwardenCloud ? `https://identity.${serverUrl.host}` : selfHostedServerUrl + "/identity/";

let { clientId, clientSecret, index, rawServerUrl, startDate, ...properties } = setup_options;

// Parse server URL
const serverUrl = new URL(rawServerUrl);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a regression, URL requires the protocol to be present, either http: or https: and throws exception when none is provided, where it was working fine before (we added it in python app backend when missing).

Suggested change
const serverUrl = new URL(rawServerUrl);
const serverUrlContainsProtocol = rawServerUrl.startsWith("http://") || rawServerUrl.startsWith("https://");
const serverUrl = new URL(serverUrlContainsProtocol ? rawServerUrl : "https://" + rawServerUrl);

@eliykat eliykat changed the title [Fix] Support for bitwarden.eu cloud [AC-2933] [Fix] Support for bitwarden.eu cloud Sep 23, 2024
@addisonbeck
Copy link
Contributor

@jpclipffel Would you be able to resolve the comments on this PR? If not, I'd like to close it. We have our own backlog item to address this, but it hasn't bubbled to the top yet and I'm not sure exactly when it will.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for EU cloud instance
5 participants