Skip to content

Comments

Fix Keycloak double-slash URL bug (#61121)#61305

Merged
vincbeck merged 2 commits intoapache:mainfrom
y-sudharshan:fix-61121-keycloak-url-normalization
Feb 2, 2026
Merged

Fix Keycloak double-slash URL bug (#61121)#61305
vincbeck merged 2 commits intoapache:mainfrom
y-sudharshan:fix-61121-keycloak-url-normalization

Conversation

@y-sudharshan
Copy link
Contributor

Fixes #61121 - Fix KeycloakAuthManager double-slash URL construction when server_url has trailing slash

Description

  • Normalize server_url in _get_token_url to prevent double-slashes
  • Add .rstrip('/') to handle trailing slashes in server_url configuration
  • Add comprehensive tests for URL normalization scenarios
  • Resolves compatibility issue with Keycloak 26.4+ strict path validation

When server_url has a trailing slash (e.g., 'https://host/auth/'), the previous implementation would create invalid URLs with double-slashes (e.g., 'https://host/auth//realms/...'), which Keycloak 26.4+ rejects with HTTP 400 'missingNormalization' error.

This fix allows users to configure server_url with or without trailing slashes while ensuring properly normalized URLs are always generated.

Changes

  • keycloak_auth_manager.py: Added URL normalization with .rstrip('/') in _get_token_url() method
  • test_keycloak_auth_manager.py: Added 4 new test methods covering URL normalization scenarios:
    • test_get_token_url_without_trailing_slash - Baseline behavior
    • test_get_token_url_with_trailing_slash - Main bug scenario
    • test_get_token_url_with_multiple_trailing_slashes - Edge case handling
    • test_get_token_url_with_root_path - Root URL scenario

Testing

  • ✅ All ruff linting checks passed
  • ✅ Code properly formatted per project standards
  • ✅ All new tests pass
  • ✅ Backward compatible with existing configurations

Impact

  • Backward Compatible: Yes - works with or without trailing slash in configuration
  • Breaking Changes: None
  • Affected Components: Keycloak auth manager token URL generation

Fixes #61121


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: GitHub Copilot

Copy link
Contributor

@SameerMesiah97 SameerMesiah97 left a comment

Choose a reason for hiding this comment

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

Just one nit. Otherwise looks good. Safe change with solid test matrix.

- Normalize server_url in _get_token_url to prevent double-slashes
- Add .rstrip('/') to handle trailing slashes in server_url configuration
- Add comprehensive tests for URL normalization scenarios
- Resolves compatibility issue with Keycloak 26.4+ strict path validation

When server_url has a trailing slash (e.g., 'https://host/auth/'),
the previous implementation would create invalid URLs with double-slashes
(e.g., 'https://host/auth//realms/...'), which Keycloak 26.4+ rejects
with HTTP 400 'missingNormalization' error.

This fix allows users to configure server_url with or without trailing
slashes while ensuring properly normalized URLs are always generated.

Fixes apache#61121
@y-sudharshan y-sudharshan force-pushed the fix-61121-keycloak-url-normalization branch from f259fbc to dfcb9f6 Compare February 2, 2026 02:49
- Consolidate 4 separate test methods into a single parametrized test
- Improves maintainability and reduces code duplication
- Covers same scenarios: no trailing slash, single slash, multiple slashes, root path
@vincbeck vincbeck merged commit 0cf2026 into apache:main Feb 2, 2026
86 checks passed
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 2, 2026

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

jason810496 pushed a commit to abhijeets25012-tech/airflow that referenced this pull request Feb 3, 2026
* Fix Keycloak double-slash URL bug (apache#61121)

- Normalize server_url in _get_token_url to prevent double-slashes
- Add .rstrip('/') to handle trailing slashes in server_url configuration
- Add comprehensive tests for URL normalization scenarios
- Resolves compatibility issue with Keycloak 26.4+ strict path validation

When server_url has a trailing slash (e.g., 'https://host/auth/'),
the previous implementation would create invalid URLs with double-slashes
(e.g., 'https://host/auth//realms/...'), which Keycloak 26.4+ rejects
with HTTP 400 'missingNormalization' error.

This fix allows users to configure server_url with or without trailing
slashes while ensuring properly normalized URLs are always generated.

Fixes apache#61121

* Refactor URL normalization tests to use parametrize

- Consolidate 4 separate test methods into a single parametrized test
- Improves maintainability and reduces code duplication
- Covers same scenarios: no trailing slash, single slash, multiple slashes, root path
Alok-kumar-priyadarshi pushed a commit to Alok-kumar-priyadarshi/airflow that referenced this pull request Feb 5, 2026
* Fix Keycloak double-slash URL bug (apache#61121)

- Normalize server_url in _get_token_url to prevent double-slashes
- Add .rstrip('/') to handle trailing slashes in server_url configuration
- Add comprehensive tests for URL normalization scenarios
- Resolves compatibility issue with Keycloak 26.4+ strict path validation

When server_url has a trailing slash (e.g., 'https://host/auth/'),
the previous implementation would create invalid URLs with double-slashes
(e.g., 'https://host/auth//realms/...'), which Keycloak 26.4+ rejects
with HTTP 400 'missingNormalization' error.

This fix allows users to configure server_url with or without trailing
slashes while ensuring properly normalized URLs are always generated.

Fixes apache#61121

* Refactor URL normalization tests to use parametrize

- Consolidate 4 separate test methods into a single parametrized test
- Improves maintainability and reduces code duplication
- Covers same scenarios: no trailing slash, single slash, multiple slashes, root path
jhgoebbert pushed a commit to jhgoebbert/airflow_Owen-CH-Leung that referenced this pull request Feb 8, 2026
* Fix Keycloak double-slash URL bug (apache#61121)

- Normalize server_url in _get_token_url to prevent double-slashes
- Add .rstrip('/') to handle trailing slashes in server_url configuration
- Add comprehensive tests for URL normalization scenarios
- Resolves compatibility issue with Keycloak 26.4+ strict path validation

When server_url has a trailing slash (e.g., 'https://host/auth/'),
the previous implementation would create invalid URLs with double-slashes
(e.g., 'https://host/auth//realms/...'), which Keycloak 26.4+ rejects
with HTTP 400 'missingNormalization' error.

This fix allows users to configure server_url with or without trailing
slashes while ensuring properly normalized URLs are always generated.

Fixes apache#61121

* Refactor URL normalization tests to use parametrize

- Consolidate 4 separate test methods into a single parametrized test
- Improves maintainability and reduces code duplication
- Covers same scenarios: no trailing slash, single slash, multiple slashes, root path
Ratasa143 pushed a commit to Ratasa143/airflow that referenced this pull request Feb 15, 2026
* Fix Keycloak double-slash URL bug (apache#61121)

- Normalize server_url in _get_token_url to prevent double-slashes
- Add .rstrip('/') to handle trailing slashes in server_url configuration
- Add comprehensive tests for URL normalization scenarios
- Resolves compatibility issue with Keycloak 26.4+ strict path validation

When server_url has a trailing slash (e.g., 'https://host/auth/'),
the previous implementation would create invalid URLs with double-slashes
(e.g., 'https://host/auth//realms/...'), which Keycloak 26.4+ rejects
with HTTP 400 'missingNormalization' error.

This fix allows users to configure server_url with or without trailing
slashes while ensuring properly normalized URLs are always generated.

Fixes apache#61121

* Refactor URL normalization tests to use parametrize

- Consolidate 4 separate test methods into a single parametrized test
- Improves maintainability and reduces code duplication
- Covers same scenarios: no trailing slash, single slash, multiple slashes, root path
choo121600 pushed a commit to choo121600/airflow that referenced this pull request Feb 22, 2026
* Fix Keycloak double-slash URL bug (apache#61121)

- Normalize server_url in _get_token_url to prevent double-slashes
- Add .rstrip('/') to handle trailing slashes in server_url configuration
- Add comprehensive tests for URL normalization scenarios
- Resolves compatibility issue with Keycloak 26.4+ strict path validation

When server_url has a trailing slash (e.g., 'https://host/auth/'),
the previous implementation would create invalid URLs with double-slashes
(e.g., 'https://host/auth//realms/...'), which Keycloak 26.4+ rejects
with HTTP 400 'missingNormalization' error.

This fix allows users to configure server_url with or without trailing
slashes while ensuring properly normalized URLs are always generated.

Fixes apache#61121

* Refactor URL normalization tests to use parametrize

- Consolidate 4 separate test methods into a single parametrized test
- Improves maintainability and reduces code duplication
- Covers same scenarios: no trailing slash, single slash, multiple slashes, root path
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.

KeycloakAuthManager constructs invalid double-slash URLs when server_url has trailing slash (breaking Keycloak 26.4+)

3 participants