Skip to content

fix: leave query strings and user info out of SAML URL errors - #261

Open
aaron-congo wants to merge 2 commits into
mainfrom
fix/saml-url-error-message
Open

aaron-congo wants to merge 2 commits into
mainfrom
fix/saml-url-error-message

Conversation

@aaron-congo

Copy link
Copy Markdown
Contributor

Summary

Problem

When the SAML plugins (federated_auth, okta) rejected an identity provider URL or a redirect sent by the identity provider, the SamlAuthError message included the whole URL. Query strings, fragments, path parameters and user info in these URLs can carry values that should not be copied into error messages, which can end up in application logs and telemetry span attributes.

A malformed redirect Location header had the same result by another route: URI.join raised URI::InvalidURIError with the whole location in its message, and the plugin wrapped that message in its SamlAuthError.

Description

Change

  • Added SamlUtils.url_for_message, which keeps the scheme, host, port and path of a URL and drops the query string, fragment, path parameters (;...) and user info. It does not parse the URL, so it also works on malformed URLs. It handles protocol-relative, backslash, single-slash and scheme-less forms, and passwords containing a raw ?, # or ;.
  • SamlUtils.validate_url! uses it in its error messages.
  • SamlUtils.absolute_redirect now raises SamlAuthError with the cleaned URL when a redirect location cannot be resolved, instead of URI::InvalidURIError.

Behavior change

  • Invalid HTTPS URL: ... messages no longer include the query string, fragment, path parameters or user info.
  • A malformed redirect location now raises SamlAuthError (Invalid redirect URL: ...) instead of URI::InvalidURIError.
  • Which URLs are accepted, and how valid redirects are followed, is unchanged.

Testing

New spec/unit/utils/saml_utils_spec.rb:

  • url_for_message with each part that is dropped, user info in its various forms, an @ in the path, and malformed URLs.
  • validate_url! messages for http, malformed and credential-bearing URLs.
  • http_request with a redirect to an http URL and with malformed redirects, and a valid relative redirect that is still followed.
  • absolute_redirect resolving a relative location and raising SamlAuthError for a malformed one.

Without the change, 12 of the 13 original specs in the file fail. The full unit test suite passes.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@aaron-congo
aaron-congo requested a review from a team as a code owner December 3, 2026 00:26
sophia-bq
sophia-bq previously approved these changes Dec 3, 2026
JuanLeee
JuanLeee previously approved these changes Dec 4, 2026

@JuanLeee JuanLeee 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.

Small nits

When an IdP URL or a redirect the IdP sends was rejected, the SamlAuthError
message held the whole URL. Query strings, fragments, path parameters and
user info can carry one-time tokens, session ids or credentials, and these
messages can reach application logs and telemetry.

The new SamlUtils.url_for_message keeps only the scheme, host, port and
path. It is used for invalid IdP URLs and for malformed redirect locations,
which previously raised URI::InvalidURIError with the whole location in its
message and now raise SamlAuthError instead.
@sophia-bq
sophia-bq dismissed stale reviews from JuanLeee and themself via 78c7def December 4, 2026 17:00
@sophia-bq
sophia-bq force-pushed the fix/saml-url-error-message branch from 7a6df8d to 78c7def Compare December 4, 2026 17:00
@sophia-bq
sophia-bq force-pushed the fix/saml-url-error-message branch from 78c7def to 085b3b8 Compare December 4, 2026 17:15
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