Do not re-validate an unchanged host/url against secure_context_uri - #24777
Open
jtauschl wants to merge 2 commits into
Open
Do not re-validate an unchanged host/url against secure_context_uri#24777jtauschl wants to merge 2 commits into
jtauschl wants to merge 2 commits into
Conversation
SecureContextUriValidator, unlike the sibling NextcloudCompatibleHostValidator applied to the same host attribute, does not guard on whether the field actually changed -- so every contract validation run re-checks the field's current value, even when an update leaves it untouched. Once a storage's host (or an XWiki provider's url) fails this check, every subsequent update that doesn't even touch the field (a rename, etc.) is permanently rejected with the same misleading error. Splits the combined validates declaration in the Nextcloud storage contract and adds the same change guard XWikiProviders::BaseContract's url validation now gets too, preserving secure_context_uri's existing run-before-the-live- network-probe ordering relative to nextcloud_compatible_host so a newly-set unsafe host is still rejected before any request is made to it. Verified live against a running instance: renaming a storage whose host was already an accepted-but-insecure value now succeeds; setting a genuinely new insecure host is still rejected, with no network probe attempted.
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes a validation bug where SecureContextUriValidator would re-run on every contract validation even when host/url was unchanged, blocking unrelated updates (e.g., renames) for records that already contained an insecure value before the validator existed.
Changes:
- Guard
secure_context_urivalidation behindmodel.host_changed?for Nextcloud storages to avoid re-validating unchanged hosts while keeping validator ordering (secure-context check still runs before any network-probing validation). - Guard
secure_context_urivalidation behindmodel.url_changed?for XWiki providers to allow unrelated updates when the URL remains unchanged. - Add regression specs covering “unchanged insecure value + unrelated change is valid” and “changed to a new insecure value remains invalid (and does not trigger network probing for Nextcloud).”
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| modules/storages/app/common/storages/adapters/providers/nextcloud/contracts/general_information_contract.rb | Splits validations and adds a host_changed? guard so secure-context checks only run when the host changes, preserving validation order before network probing. |
| modules/storages/spec/contracts/storages/storages/nextcloud_update_contract_spec.rb | Adds regression coverage ensuring unchanged insecure hosts don’t block unrelated updates and don’t trigger metadata discovery requests. |
| modules/wikis/app/contracts/wikis/xwiki_providers/base_contract.rb | Adds a url_changed? guard so secure-context validation only runs when the URL is being changed. |
| modules/wikis/spec/contracts/wikis/xwiki_providers/base_contract_spec.rb | Adds regression coverage for unchanged insecure URLs being allowed on unrelated updates, while still rejecting newly-set insecure URLs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Layout/HashAlignment expects the second line's key to align with the first line's hash-argument key column.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://community.openproject.org/wp/OP-19970
Summary
SecureContextUriValidator, applied to Storages::NextcloudStorage#host and Wikis::XWikiProvider#url, does not guard on whether the field actually changed — unlike its siblingNextcloudCompatibleHostValidatoron the samehostattribute, which already checkscontract.model.changed_attributes.include?(attribute). As a result, every contract validation run re-checks the field's current value, even when an update leaves it untouched.Once a storage's
host(or an XWiki provider'surl) predates this check or otherwise fails it, every subsequent update that doesn't even touch that field — a rename, or any other unrelated-field change — is permanently rejected with the same "Secure Context" error.Fixes the bug reported at OP-19970.
Changes
validates :host, secure_context_uri: true, nextcloud_compatible_host: truedeclaration inStorages::Adapters::Providers::Nextcloud::Contracts::GeneralInformationContract, adding amodel.host_changed?guard tosecure_context_urispecifically. Order is preserved (secure_context_uristill runs before the network-probingnextcloud_compatible_host), so a newly-set unsafe host is still rejected before any live request is made to it.model.url_changed?guard toWikis::XWikiProviders::BaseContract'ssecure_context_urivalidation.Verification
Verified live against a running OpenProject 17.7.1 instance (could not run the RSpec suite locally — no working Ruby/bundler setup in this environment; the new spec files were only syntax-checked with
ruby -c, please verify on CI):hostwashttp://nc.openproject.com(unchanged, insecure) — before: HTTP 422 "Secure Context" error; after: succeeds,hostunchanged.hostto a new insecure value (http://another-unsafe-host.example) — still correctly rejected, confirmed no network probe was attempted before rejection (rejection returned in ~0.07s).url; newly-set insecureurl) verified the same way via a direct contract call.nextcloud_compatible_host's probe exactly as before.Test plan
modules/storages/spec/contracts/storages/storages/nextcloud_update_contract_spec.rbandmodules/wikis/spec/contracts/wikis/xwiki_providers/base_contract_spec.rb