Skip to content

Hub: Trust on first use - #4179

Merged
overheadhunter merged 31 commits into
developfrom
feature/admin-config-allowlist
Mar 12, 2026
Merged

overheadhunter merged 31 commits into
developfrom
feature/admin-config-allowlist

Conversation

@overheadhunter

Copy link
Copy Markdown
Member

This change introduces support for

  1. New admin property cryptomator.hub.allowedHosts to allowlist hub instances
  2. New admin property cryptomator.hub.enableTrustOnFirstUse to enable trust on first use when unlocking a Hub vault

In any case, a check is prepended to the Hub unlock workflow to verify whether a host is trustworthy before making any connection attempts.

@coderabbitai

coderabbitai Bot commented Mar 11, 2026 •

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • ✅ Review completed - (🔄 Check again to review again)

Walkthrough

Adds Trust-On-First-Use (TOFU) support for the hub: new environment properties for allowed hosts and TOFU, persistent settings for trusted hosts, VM flags in run configurations, two new JavaFX dialogs and controllers (check-host-trust and untrusted-host), DI bindings and scenes, updates to the hub key-loading flow to present a host-trust check, a preferences UI button to reset trusted hosts, i18n strings, and unit tests for host-trust helpers.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Feature: Files in use #4078: Modifies HubKeyLoadingStrategy constructor/parameters and interacts with the same scene/flow changes introduced here.

Suggested reviewers

  • infeo
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Hub: Trust on first use' directly relates to the main change: introducing trust-on-first-use support for Hub vaults, which is the primary objective across all modifications.
Description check ✅ Passed The description accurately outlines the key changes: new admin properties for allowlisting and enabling TOFU, plus prepending a host verification check to the Hub unlock workflow, all of which are evident in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/admin-config-allowlist

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

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.

Pull request overview

This PR introduces a “trust on first use” (TOFU) flow for Cryptomator Hub connections, including UI screens to confirm/deny host trust, persistence of trusted hosts in settings, and a preferences action to reset trusted hosts. It also adds environment/admin properties to control Hub allowed hosts and whether TOFU is enabled.

Changes:

  • Add Hub host trust verification flow (check-trust dialog + untrusted-host dialog) before proceeding to the auth flow.
  • Persist trusted Hub hosts in settings.json and add a “Reset trusted hosts” preferences button.
  • Add environment/admin property support for Hub allowed-hosts and TOFU enablement; include a small unit test for authority/allowlist logic.

Reviewed changes

Copilot reviewed 16 out of 22 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java New controller implementing the TOFU/allowlist decision logic and scene transitions.
src/main/java/org/cryptomator/ui/keyloading/hub/UntrustedHostController.java New controller for the “blocked/untrusted host” dialog.
src/main/resources/fxml/hub_check_host_trust.fxml New UI for asking the user to trust one/multiple hosts.
src/main/resources/fxml/hub_untrusted_host.fxml New UI shown when a Hub host is blocked.
src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingStrategy.java Starts Hub unlock flow with the host-trust scene instead of auth flow.
src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java Wires new scenes/controllers into DI graph.
src/main/java/org/cryptomator/ui/common/FxmlFile.java Registers new FXML files.
src/main/java/org/cryptomator/common/Environment.java Adds Hub-related property names + accessors for allowed hosts and TOFU enablement.
src/main/java/org/cryptomator/common/settings/SettingsJson.java Adds trustedHosts to settings JSON model.
src/main/java/org/cryptomator/common/settings/Settings.java Adds observable trustedHosts and serialization.
src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java Adds “Reset trusted hosts” action and enablement binding.
src/main/resources/fxml/preferences_general.fxml Adds reset button (visible only when TOFU is enabled).
src/main/resources/i18n/strings.properties Adds i18n strings for new dialogs and reset button.
src/test/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustControllerTest.java Adds parameterized tests for authority canonicalization and allowlist checking.
src/main/java/org/cryptomator/launcher/AdminPropertiesFactory.java Allows overriding Hub host/TOFU properties via admin config.
src/main/java/org/cryptomator/ui/keyloading/hub/AuthFlowController.java Removes now-unused imports.
.idea/runConfigurations/*.xml Enables TOFU in IDE run configs via VM parameter.
Files not reviewed (6)
  • .idea/runConfigurations/Cryptomator_Linux.xml: Language not supported
  • .idea/runConfigurations/Cryptomator_Linux_Dev.xml: Language not supported
  • .idea/runConfigurations/Cryptomator_Windows.xml: Language not supported
  • .idea/runConfigurations/Cryptomator_Windows_Dev.xml: Language not supported
  • .idea/runConfigurations/Cryptomator_macOS.xml: Language not supported
  • .idea/runConfigurations/Cryptomator_macOS_Dev.xml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 9

🧹 Nitpick comments (4)
.idea/runConfigurations/Cryptomator_Linux_Dev.xml (1)

5-5: Avoid forcing TOFU in the shared default dev configuration.

Hardcoding -Dcryptomator.hub.enableTrustOnFirstUse=true here means everyone launching Cryptomator Linux Dev will always exercise the TOFU path. That makes local behavior differ from the default product behavior and can hide regressions in the "TOFU disabled" flow. Prefer a separate opt-in run configuration for TOFU testing, or leave this flag unset unless it is explicitly needed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.idea/runConfigurations/Cryptomator_Linux_Dev.xml at line 5, The run
configuration's VM_PARAMETERS currently forces TOFU by including
"-Dcryptomator.hub.enableTrustOnFirstUse=true"; remove that flag from the
VM_PARAMETERS string so the default behavior is preserved, and if TOFU testing
is needed create a separate opt-in run configuration that includes
"-Dcryptomator.hub.enableTrustOnFirstUse=true" (or explicitly set it to false in
the shared config) rather than hardcoding it into the shared default.
.idea/runConfigurations/Cryptomator_Windows.xml (1)

5-5: Keep TOFU out of the shared default Windows launcher.

Setting cryptomator.hub.enableTrustOnFirstUse=true here makes the checked-in Cryptomator Windows profile silently diverge from the default app behavior, so Windows QA from IntelliJ will stop exercising the non-TOFU path unless someone notices the flag. I'd keep this profile neutral and add a separate ... (TOFU) run configuration if you want a convenient opt-in launcher.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.idea/runConfigurations/Cryptomator_Windows.xml at line 5, The shared
Windows run configuration currently forces TOFU by setting the JVM property
cryptomator.hub.enableTrustOnFirstUse=true inside the VM_PARAMETERS option;
remove that property from the VM_PARAMETERS value so the checked-in Cryptomator
Windows profile remains neutral, and instead add a separate run configuration
(e.g., "Cryptomator_Windows (TOFU)") that contains the
cryptomator.hub.enableTrustOnFirstUse=true JVM parameter for opt‑in testing.
src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java (1)

110-112: Let missing FXML injection fail fast here.

resetTrustedHostsButton is required by preferences_general.fxml, so this null-guard only hides broken fx:id wiring during initialization.

♻️ Proposed cleanup
-		if (resetTrustedHostsButton != null) {
-			resetTrustedHostsButton.disableProperty().bind(Bindings.isEmpty(settings.trustedHosts));
-		}
+		resetTrustedHostsButton.disableProperty().bind(Bindings.isEmpty(settings.trustedHosts));

Based on learnings: In the Cryptomator project, null checks for JavaFX FXML injected components in the initialize method are unnecessary, as null values would indicate a severe issue with the JavaFX framework.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java`
around lines 110 - 112, The null-guard around resetTrustedHostsButton should be
removed so FXML injection failures fail fast: in the initialize method bind
resetTrustedHostsButton.disableProperty() directly to
Bindings.isEmpty(settings.trustedHosts) (referencing resetTrustedHostsButton and
settings.trustedHosts) instead of wrapping it in "if (resetTrustedHostsButton !=
null)" so missing fx:id wiring surfaces immediately during startup.
src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java (1)

149-160: Consider documenting the port normalization behavior.

The authority normalization assumes port 80 always means HTTP and port 443 always means HTTPS. While unusual, configurations like HTTPS on port 80 would be normalized incorrectly. Since this affects how admins must configure cryptomator.hub.allowedHosts, consider adding a brief doc comment explaining the normalization rules.

📝 Suggested documentation
+/**
+ * Returns a normalized authority string for the given URI.
+ * <p>
+ * Normalization rules:
+ * - Port 80 is normalized to "http://host" (implicit HTTP port)
+ * - Port 443 is normalized to "https://host" (implicit HTTPS port)
+ * - Other ports include the port number: "scheme://host:port"
+ * - Default port (-1) uses the URI's scheme: "scheme://host"
+ */
 public static String getAuthority(URI uri) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java`
around lines 149 - 160, The getAuthority(String) / getAuthority(URI) methods
normalize URIs by mapping port -1 to "<scheme>://<host>", port 80 to
"http://<host>", port 443 to "https://<host>", and otherwise including the
explicit port; document this behavior with a Javadoc on both methods (or at
least on getAuthority(URI)) that clearly states the normalization rules and
warns that explicit non-standard mappings (e.g. HTTPS on port 80) will be
rewritten to the default scheme form, so admins configuring
cryptomator.hub.allowedHosts understand the implications.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.idea/runConfigurations/Cryptomator_Linux.xml:
- Line 5: The run configuration currently enables trust-on-first-use via the VM
parameter cryptomator.hub.enableTrustOnFirstUse in the VM_PARAMETERS option and
points to the real settings path (cryptomator.settingsPath), which will persist
TOFU state into the user's normal profile; remove or disable the
cryptomator.hub.enableTrustOnFirstUse flag from this shared production-profile
run config and either create a separate dev run configuration that uses an
isolated settingsPath (e.g., a temp or project-local path) or explicitly
override cryptomator.settingsPath for local runs so TOFU state is not written to
the real user settings.

In @.idea/runConfigurations/Cryptomator_macOS.xml:
- Line 8: The shared macOS run configuration currently enables
Trust-On-First-Use via the VM parameter
-Dcryptomator.hub.enableTrustOnFirstUse=true and points at the normal user
settings path via -Dcryptomator.settingsPath=".../Cryptomator/settings.json";
remove or relocate the -Dcryptomator.hub.enableTrustOnFirstUse flag from this
shared profile and either (a) add it only to a developer-local run configuration
or (b) ensure the shared config uses an isolated settings path (change the
-Dcryptomator.settingsPath value to a sandboxed/dev-only directory) so trusted
hosts are not persisted into real user profiles.

In `@src/main/java/org/cryptomator/common/Environment.java`:
- Around line 156-159: The method hubAllowedHosts() currently splits the
property value and returns a set that can contain a single empty string when the
property is empty; update hubAllowedHosts() to trim tokens and filter out
blank/empty tokens before collecting (i.e., after mapping String::trim, drop
entries where the trimmed string is empty) so an empty property yields an empty
set; reference the HUB_ALLOWED_HOSTS_PROP_NAME and allowedHubHostsString
variables and the hubAllowedHosts() method when making the change.

In `@src/main/java/org/cryptomator/common/settings/Settings.java`:
- Line 125: The Settings constructor wraps SettingsJson.trustedHosts (which may
be an immutable Set.of()) directly into an observable set, causing
UnsupportedOperationException when callers (e.g.,
settings.trustedHosts.addAll(...) in the hub trust flow or
settings.trustedHosts.clear() from preferences) try to mutate it; fix by
creating a mutable copy of json.trustedHosts before making it observable (e.g.,
construct a new HashSet<>(json.trustedHosts) and then call
FXCollections.observableSet(...) so trustedHosts is backed by a mutable
collection).

In `@src/main/java/org/cryptomator/common/settings/SettingsJson.java`:
- Around line 104-105: The trustedHosts field in SettingsJson can be
deserialized as null causing an NPE downstream; annotate the Set<String>
trustedHosts field in SettingsJson with Jackson's `@JsonSetter`(nulls =
Nulls.AS_EMPTY) (and optionally contentNulls = Nulls.AS_EMPTY) and import
com.fasterxml.jackson.annotation.Nulls so any incoming JSON "trustedHosts": null
is coerced to an empty set during deserialization, or alternatively initialize
the field to Collections.emptySet() and ensure deserialization respects that
default.

In
`@src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java`:
- Around line 75-77: The check in CheckHostTrustController that currently uses
isHttpHost() && !isLocalhost() allows a mix of HTTP endpoints to bypass denial;
change the condition so it denies if any HTTP endpoint is non-localhost.
Implement or call a predicate that verifies “all HTTP endpoints are localhost”
(e.g., allHttpHttpEndpointsAreLocalhost() or similar) and replace the current
condition with isHttpHost() && !allHttpHttpEndpointsAreLocalhost(); apply the
same fix to the other identical block around lines 130-140 and keep calling
deny() when the predicate fails.
- Around line 124-128: The current isCryptomatorCloud() uses
endsWith(TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN) which allows spoofing; update the
check in isCryptomatorCloud() to accept only an exact match or a proper
subdomain by comparing canonicalHubHost and canonicalAuthHost against either
TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN (equalsIgnoreCase) or ending with "." +
TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN (case-insensitive), ensuring you normalize/trim
any trailing dots and use the existing canonicalHubHost/canonicalAuthHost
variables and TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN constant for the comparisons.

In `@src/main/resources/fxml/hub_untrusted_host.fxml`:
- Around line 36-42: The dialog currently only shows static resource keys
(hub.untrustedHost.message and hub.untrustedHost.description); add a bound Label
to display the actual rejected host by giving one of the Labels an fx:id (e.g.
fx:id="blockedAuthorityLabel") and bind its text to a controller StringProperty
(e.g. blockedAuthorityProperty) or use Bindings.format to insert the property
into a parameterized resource string; then expose blockedAuthorityProperty on
the dialog controller class and set it to the refused authority when the dialog
is created so the FXML label shows the blocked host.

In
`@src/test/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustControllerTest.java`:
- Line 24: The test instantiates CheckHostTrustController using Mockito.mock()
with no arguments which doesn't compile; update the constructor call in
CheckHostTrustControllerTest to pass explicit class types to each
Mockito.mock(...) call that corresponds to the constructor parameters of
CheckHostTrustController (or replace those dummy mocks with `@Mock` annotated
fields initialized by MockitoJUnit/MockitoExtension). Ensure the types you pass
match the parameter types of the CheckHostTrustController constructor so the
call compiles.

---

Nitpick comments:
In @.idea/runConfigurations/Cryptomator_Linux_Dev.xml:
- Line 5: The run configuration's VM_PARAMETERS currently forces TOFU by
including "-Dcryptomator.hub.enableTrustOnFirstUse=true"; remove that flag from
the VM_PARAMETERS string so the default behavior is preserved, and if TOFU
testing is needed create a separate opt-in run configuration that includes
"-Dcryptomator.hub.enableTrustOnFirstUse=true" (or explicitly set it to false in
the shared config) rather than hardcoding it into the shared default.

In @.idea/runConfigurations/Cryptomator_Windows.xml:
- Line 5: The shared Windows run configuration currently forces TOFU by setting
the JVM property cryptomator.hub.enableTrustOnFirstUse=true inside the
VM_PARAMETERS option; remove that property from the VM_PARAMETERS value so the
checked-in Cryptomator Windows profile remains neutral, and instead add a
separate run configuration (e.g., "Cryptomator_Windows (TOFU)") that contains
the cryptomator.hub.enableTrustOnFirstUse=true JVM parameter for opt‑in testing.

In
`@src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java`:
- Around line 149-160: The getAuthority(String) / getAuthority(URI) methods
normalize URIs by mapping port -1 to "<scheme>://<host>", port 80 to
"http://<host>", port 443 to "https://<host>", and otherwise including the
explicit port; document this behavior with a Javadoc on both methods (or at
least on getAuthority(URI)) that clearly states the normalization rules and
warns that explicit non-standard mappings (e.g. HTTPS on port 80) will be
rewritten to the default scheme form, so admins configuring
cryptomator.hub.allowedHosts understand the implications.

In
`@src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java`:
- Around line 110-112: The null-guard around resetTrustedHostsButton should be
removed so FXML injection failures fail fast: in the initialize method bind
resetTrustedHostsButton.disableProperty() directly to
Bindings.isEmpty(settings.trustedHosts) (referencing resetTrustedHostsButton and
settings.trustedHosts) instead of wrapping it in "if (resetTrustedHostsButton !=
null)" so missing fx:id wiring surfaces immediately during startup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8d57c4d9-d3be-44c4-85d5-a9ac80c55402

📥 Commits

Reviewing files that changed from the base of the PR and between b8413a2 and 096aeb0.

📒 Files selected for processing (22)
  • .idea/runConfigurations/Cryptomator_Linux.xml
  • .idea/runConfigurations/Cryptomator_Linux_Dev.xml
  • .idea/runConfigurations/Cryptomator_Windows.xml
  • .idea/runConfigurations/Cryptomator_Windows_Dev.xml
  • .idea/runConfigurations/Cryptomator_macOS.xml
  • .idea/runConfigurations/Cryptomator_macOS_Dev.xml
  • src/main/java/org/cryptomator/common/Environment.java
  • src/main/java/org/cryptomator/common/settings/Settings.java
  • src/main/java/org/cryptomator/common/settings/SettingsJson.java
  • src/main/java/org/cryptomator/launcher/AdminPropertiesFactory.java
  • src/main/java/org/cryptomator/ui/common/FxmlFile.java
  • src/main/java/org/cryptomator/ui/keyloading/hub/AuthFlowController.java
  • src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java
  • src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java
  • src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingStrategy.java
  • src/main/java/org/cryptomator/ui/keyloading/hub/UntrustedHostController.java
  • src/main/java/org/cryptomator/ui/preferences/GeneralPreferencesController.java
  • src/main/resources/fxml/hub_check_host_trust.fxml
  • src/main/resources/fxml/hub_untrusted_host.fxml
  • src/main/resources/fxml/preferences_general.fxml
  • src/main/resources/i18n/strings.properties
  • src/test/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustControllerTest.java
💤 Files with no reviewable changes (1)
  • src/main/java/org/cryptomator/ui/keyloading/hub/AuthFlowController.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java (2)

75-80: ⚠️ Potential issue | 🔴 Critical

Reject any non-localhost HTTP endpoint before auto-trusting it.

isCryptomatorCloud() and containsAllowedHosts(...) run before the HTTP guard, so non-localhost http:// endpoints can still be trusted. And once the guard is reached, isHttpHost() && !isLocalhost() only rejects when neither endpoint is localhost, so a mixed config like http://evil + http://localhost still slips through.

🔒 Suggested fix
@@
-		} else if (isCryptomatorCloud()) {
-			trust(); // trust *.cryptomator.cloud by default, domain is owned by Cryptomator maintainers
-		} else if (containsAllowedHosts(env.hubAllowedHosts())) {
-			trust(); // trust hosts explicitly allowlisted via system property
-		} else if (isHttpHost() && !isLocalhost()) {
+		} else if (hasUnsafeHttpEndpoint()) {
 			LOG.warn("Denying attempt to connect to hub instance via unencrypted HTTP.");
 			deny(); // never trust http hosts except for local testing
+		} else if (isCryptomatorCloud()) {
+			trust(); // trust *.cryptomator.cloud by default, domain is owned by Cryptomator maintainers
+		} else if (containsAllowedHosts(env.hubAllowedHosts())) {
+			trust(); // trust hosts explicitly allowlisted via system property
 		}
@@
-	private boolean isHttpHost() {
-		return "http".equalsIgnoreCase(canonicalHubUri.getScheme()) || "http".equalsIgnoreCase(canonicalAuthUri.getScheme());
-	}
-
-	private boolean isLocalhost() {
-		return "localhost".equalsIgnoreCase(canonicalHubUri.getHost()) || "localhost".equalsIgnoreCase(canonicalAuthUri.getHost());
+	private boolean hasUnsafeHttpEndpoint() {
+		return isUnsafeHttp(canonicalHubUri) || isUnsafeHttp(canonicalAuthUri);
+	}
+
+	private boolean isUnsafeHttp(URI uri) {
+		return "http".equalsIgnoreCase(uri.getScheme()) && !"localhost".equalsIgnoreCase(uri.getHost());
 	}

Also applies to: 133-139

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java`
around lines 75 - 80, The current trust decision in CheckHostTrustController
allows non-localhost http:// endpoints to be auto-trusted because
isCryptomatorCloud() and containsAllowedHosts(...) run before the HTTP guard;
move or enforce the HTTP-localhost guard earlier by rejecting any non-localhost
HTTP endpoints before any auto-trust checks: ensure isHttpHost() &&
!isLocalhost() is evaluated prior to calling isCryptomatorCloud() or
containsAllowedHosts(env.hubAllowedHosts()) (or add an explicit && !isHttpHost()
check to the trust branches), updating both the earlier block around trust() and
the duplicated block at lines 133-139 so that non-localhost HTTP endpoints are
always denied before trusting.

128-130: ⚠️ Potential issue | 🔴 Critical

Restrict cryptomator.cloud auto-trust to the real domain boundary.

endsWith("cryptomator.cloud") also matches hosts like fakecryptomator.cloud, so this branch can auto-trust attacker-controlled domains without any prompt.

🔒 Suggested fix
+import java.util.Locale;
@@
 	private boolean isCryptomatorCloud() {
-		return canonicalHubUri.getHost().endsWith(TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN)
-				&& canonicalAuthUri.getHost().endsWith(TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN);
+		return isTrustedCryptomatorDomain(canonicalHubUri.getHost())
+				&& isTrustedCryptomatorDomain(canonicalAuthUri.getHost());
+	}
+
+	private boolean isTrustedCryptomatorDomain(String host) {
+		if (host == null || host.isBlank()) {
+			return false;
+		}
+		var normalizedHost = host.endsWith(".") ? host.substring(0, host.length() - 1) : host;
+		var lowerCaseHost = normalizedHost.toLowerCase(Locale.ROOT);
+		return TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN.equals(lowerCaseHost)
+				|| lowerCaseHost.endsWith("." + TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN);
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java`
around lines 128 - 130, The isCryptomatorCloud() method currently uses
endsWith(TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN) which allows hosts like
fakecryptomator.cloud; change the check on canonicalHubUri.getHost() and
canonicalAuthUri.getHost() to normalize to lower-case and verify either exact
match equalsIgnoreCase(TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN) or a proper subdomain
by checking endsWith("." + TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN) (i.e.,
host.equalsIgnoreCase(...) || host.endsWith("." + ...)); ensure null-safe access
to getHost() before applying these comparisons so only the real
cryptomator.cloud and its true subdomains are auto-trusted.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java`:
- Around line 150-155: The getAuthority(URI uri) method collapses ports to
default schemes incorrectly (e.g., https://host:80 -> http://host). Update
getAuthority(URI uri) so it preserves the original uri.getScheme() when
collapsing default ports: treat port == -1 as scheme://host, treat port == 80 as
scheme://host only if uri.getScheme().equalsIgnoreCase("http"), treat port ==
443 as scheme://host only if uri.getScheme().equalsIgnoreCase("https"), and in
all other cases return scheme://host:port; adjust the switch/condition logic
accordingly to use uri.getScheme(), uri.getHost(), and uri.getPort().

---

Duplicate comments:
In
`@src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java`:
- Around line 75-80: The current trust decision in CheckHostTrustController
allows non-localhost http:// endpoints to be auto-trusted because
isCryptomatorCloud() and containsAllowedHosts(...) run before the HTTP guard;
move or enforce the HTTP-localhost guard earlier by rejecting any non-localhost
HTTP endpoints before any auto-trust checks: ensure isHttpHost() &&
!isLocalhost() is evaluated prior to calling isCryptomatorCloud() or
containsAllowedHosts(env.hubAllowedHosts()) (or add an explicit && !isHttpHost()
check to the trust branches), updating both the earlier block around trust() and
the duplicated block at lines 133-139 so that non-localhost HTTP endpoints are
always denied before trusting.
- Around line 128-130: The isCryptomatorCloud() method currently uses
endsWith(TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN) which allows hosts like
fakecryptomator.cloud; change the check on canonicalHubUri.getHost() and
canonicalAuthUri.getHost() to normalize to lower-case and verify either exact
match equalsIgnoreCase(TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN) or a proper subdomain
by checking endsWith("." + TRUSTED_CRYPTOMATOR_CLOUD_DOMAIN) (i.e.,
host.equalsIgnoreCase(...) || host.endsWith("." + ...)); ensure null-safe access
to getHost() before applying these comparisons so only the real
cryptomator.cloud and its true subdomains are auto-trusted.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 18e227a3-42f0-4f74-bef1-6e6016ecf79c

📥 Commits

Reviewing files that changed from the base of the PR and between 096aeb0 and 596829b.

📒 Files selected for processing (1)
  • src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (2)
src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java (2)

150-155: ⚠️ Potential issue | 🟠 Major

Preserve the original scheme when normalizing default ports.

Lines 151-154 currently derive the scheme from the port, so https://host:80 becomes http://host and http://host:443 becomes https://host. That can collapse distinct trust entries across the consistency check, allowlist matching, and TOFU persistence.

🛠️ Proposed fix
 public static String getAuthority(URI uri) {
-		return switch (uri.getPort()) {
-			case -1 -> "%s://%s".formatted(uri.getScheme(), uri.getHost());
-			case 80 -> "http://%s".formatted(uri.getHost());
-			case 443 -> "https://%s".formatted(uri.getHost());
-			default -> "%s://%s:%s".formatted(uri.getScheme(), uri.getHost(), uri.getPort());
-		};
+		var scheme = uri.getScheme();
+		var host = uri.getHost();
+		var port = uri.getPort();
+		var hasDefaultPort = port == -1
+				|| ("http".equalsIgnoreCase(scheme) && port == 80)
+				|| ("https".equalsIgnoreCase(scheme) && port == 443);
+		return hasDefaultPort
+				? "%s://%s".formatted(scheme, host)
+				: "%s://%s:%s".formatted(scheme, host, port);
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java`
around lines 150 - 155, The getAuthority(URI uri) method currently maps ports 80
and 443 to "http" and "https" respectively, which overrides the original URI
scheme; change the logic so default-port omission preserves uri.getScheme()
instead of inferring scheme from port (i.e., when uri.getPort() is 80 or 443,
return "%s://%s" using uri.getScheme() and uri.getHost()); keep the existing
behaviors for port -1 and the default case that includes the explicit port so
getAuthority in CheckHostTrustController.java consistently reflects the original
scheme.

79-81: ⚠️ Potential issue | 🟠 Major

Require both HTTP endpoints to be localhost.

With the current OR logic in isLocalhost(), Line 79 only rejects HTTP when neither endpoint is localhost. A config like http://evil.example plus http://localhost still bypasses the deny path.

🔒 Proposed fix
 private boolean isLocalhost() {
-		return "localhost".equalsIgnoreCase(canonicalHubUri.getHost()) || "localhost".equalsIgnoreCase(canonicalAuthUri.getHost());
+		return "localhost".equalsIgnoreCase(canonicalHubUri.getHost()) && "localhost".equalsIgnoreCase(canonicalAuthUri.getHost());
 }

Also applies to: 137-138

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java`
around lines 79 - 81, The current check uses isHttpHost() && !isLocalhost(),
which treats isLocalhost() as true if either endpoint is localhost and thus
allows a mix of localhost and external HTTP; change the logic so that both HTTP
endpoints must be localhost before skipping the deny call: replace the single
isLocalhost() check with an explicit AND of the two localhost checks (or adjust
isLocalhost() to only return true when both endpoints are localhost) so that the
condition becomes isHttpHost() && !(bothEndpointsAreLocalhost) and still calls
deny() otherwise; apply the same change at the other occurrence around the lines
similar to 137–138 in CheckHostTrustController (referencing isHttpHost(),
isLocalhost(), and deny()).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In
`@src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java`:
- Around line 150-155: The getAuthority(URI uri) method currently maps ports 80
and 443 to "http" and "https" respectively, which overrides the original URI
scheme; change the logic so default-port omission preserves uri.getScheme()
instead of inferring scheme from port (i.e., when uri.getPort() is 80 or 443,
return "%s://%s" using uri.getScheme() and uri.getHost()); keep the existing
behaviors for port -1 and the default case that includes the explicit port so
getAuthority in CheckHostTrustController.java consistently reflects the original
scheme.
- Around line 79-81: The current check uses isHttpHost() && !isLocalhost(),
which treats isLocalhost() as true if either endpoint is localhost and thus
allows a mix of localhost and external HTTP; change the logic so that both HTTP
endpoints must be localhost before skipping the deny call: replace the single
isLocalhost() check with an explicit AND of the two localhost checks (or adjust
isLocalhost() to only return true when both endpoints are localhost) so that the
condition becomes isHttpHost() && !(bothEndpointsAreLocalhost) and still calls
deny() otherwise; apply the same change at the other occurrence around the lines
similar to 137–138 in CheckHostTrustController (referencing isHttpHost(),
isLocalhost(), and deny()).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 30fee2b3-8ded-4a6d-ac30-4084fb564830

📥 Commits

Reviewing files that changed from the base of the PR and between 596829b and d803a1d.

📒 Files selected for processing (3)
  • src/main/java/org/cryptomator/common/Environment.java
  • src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java
  • src/main/java/org/cryptomator/ui/keyloading/hub/HubKeyLoadingModule.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/cryptomator/common/Environment.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java (1)

128-138: Consider defensive null checks for getHost() and getScheme() calls.

These methods can return null for malformed URIs or opaque URI schemes. While the URIs are expected to be well-formed from the Hub server, adding null guards would make the code more defensive.

// Example: getHost() returns null for "mailto:[email protected]"

This is low-risk since the Hub config is server-provided and presumably validated, but worth noting.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java`
around lines 128 - 138, Add null guards for URI host/scheme access in
isAllCryptomatorCloud(), isAnyHttpHost(), and isAllLocalhost(): before calling
getHost() or getScheme() use null checks (or short-circuit boolean expressions)
so you only call endsWith/equalsIgnoreCase on non-null strings; e.g., ensure
canonicalHubUri.getHost() != null && canonicalAuthUri.getHost() != null before
endsWith(...) and canonicalHubUri.getScheme() != null before
equalsIgnoreCase(...), returning false if any required part is null.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java`:
- Around line 128-138: Add null guards for URI host/scheme access in
isAllCryptomatorCloud(), isAnyHttpHost(), and isAllLocalhost(): before calling
getHost() or getScheme() use null checks (or short-circuit boolean expressions)
so you only call endsWith/equalsIgnoreCase on non-null strings; e.g., ensure
canonicalHubUri.getHost() != null && canonicalAuthUri.getHost() != null before
endsWith(...) and canonicalHubUri.getScheme() != null before
equalsIgnoreCase(...), returning false if any required part is null.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dcaef9a5-0cd4-413b-9407-e22e7921b872

📥 Commits

Reviewing files that changed from the base of the PR and between d803a1d and d196b66.

📒 Files selected for processing (1)
  • src/main/java/org/cryptomator/ui/keyloading/hub/CheckHostTrustController.java

use singular because in most cases hub and auth are on either pre-trusted or on the same domain
@overheadhunter
overheadhunter merged commit 6b82abc into develop Mar 12, 2026
5 checks passed
@overheadhunter
overheadhunter deleted the feature/admin-config-allowlist branch March 12, 2026 11:29
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.

3 participants