Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions apps/agentstack-server/src/agentstack_server/api/auth/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ async def discover_issuer(provider: OidcProvider) -> AuthorizationServerMetadata
response.raise_for_status()
metadata = AuthorizationServerMetadata(response.json())
metadata.validate_issuer()
metadata.validate_jwks_uri()
metadata.validate_introspection_endpoint()
if provider.issuer.scheme == "https":
metadata.validate_jwks_uri()
metadata.validate_introspection_endpoint()
Comment on lines +181 to +183
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The code skips validation of the JWKS URI and introspection endpoint when the OIDC issuer uses the 'http' scheme. This is done to support the insecure_transport configuration. However, by skipping these validations, the application may accept insecure or malformed metadata from an unencrypted source, which could be manipulated by an attacker to point to malicious endpoints.

except Exception as e:
# Fallback to OIDC 1.0
try:
Expand All @@ -188,8 +189,9 @@ async def discover_issuer(provider: OidcProvider) -> AuthorizationServerMetadata
response.raise_for_status()
metadata = OpenIDProviderMetadata(response.json())
metadata.validate_issuer()
metadata.validate_jwks_uri()
metadata.validate_introspection_endpoint()
if provider.issuer.scheme == "https":
metadata.validate_jwks_uri()
metadata.validate_introspection_endpoint()
Comment on lines +192 to +194
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This conditional block is a duplicate of the one on lines 181-183. To adhere to the Don't Repeat Yourself (DRY) principle and improve maintainability, consider extracting this logic into a separate helper function. This would make the code cleaner and reduce redundancy.

except Exception as fallback_e:
logger.warning(f"Issuer discovery fallback failed for provider {provider.issuer}: {fallback_e}")
raise fallback_e from e
Expand Down
4 changes: 2 additions & 2 deletions apps/agentstack-server/src/agentstack_server/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def provider(self) -> OidcProvider:
@model_validator(mode="after")
def validate_auth(self):
if self.insecure_transport:
if self.issuer.scheme != "http" or self.issuer.host != "keycloak":
raise ValueError("Insecure transport is only allowed for internal keycloak!")
if self.issuer.scheme != "http":
raise ValueError("Insecure transport is only allowed when the issuer URL uses http:// scheme!")
Comment on lines +134 to +135
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The application allows enabling insecure transport for OIDC authentication for any host. When insecure_transport is enabled and an HTTP issuer is used, sensitive credentials such as the client_secret will be transmitted over an unencrypted channel during token introspection and basic authentication. This exposes the credentials to interception by a man-in-the-middle attacker. The previous implementation restricted this to a specific host ('keycloak'), which likely limited the risk to internal traffic.


os.environ["AUTHLIB_INSECURE_TRANSPORT"] = "1"
logger.warning(
Expand Down
Loading