Refactor: Modernize TrustChainBuilder and Fix Validation Logic #333
+87
−63
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.
His pull request introduces two significant improvements: the modernization of the TrustChainBuilder class to use a recursive approach and the correction of a critical logic flaw in the authorization request validation.
1. TrustChainBuilder Refactoring (spid_cie_oidc/entity/trust_chain.py)
The apply_metadata_policy method in the TrustChainBuilder class has been completely refactored. The previous logic, based on a complex while loop, has been replaced with a cleaner, more modern recursive approach (Depth-First Search).
Benefits:
Improved Readability: The recursive logic, broken down into helper functions, makes the trust path discovery flow much easier to understand.
Maintainability: Smaller functions with single responsibilities are easier to maintain and debug.
Reduced Complexity: Eliminates the need for control flag variables and complex state management within the loop.
2. Logic Fix in validate_authz Validation (spid_cie_oidc/provider/views/authz_request_view.py)
An inverted logic flaw was identified and corrected in the validation that checks whether the redirect_uri belongs to the client_id's domain.
Old Behavior (Incorrect): The code threw a ValidationException if the client_id was present in the redirect_uri, effectively punishing valid requests.
New Behavior (Correct): The if condition has been negated (if not ...). Now, the exception is correctly thrown only if the client_id is not present in the redirect_uri.
This fix is crucial for security, as it ensures the expected protection against open redirect attacks.
old:
