-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify the GSSP response is valid #307
Conversation
a7a5533
to
8dfe2c1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small suggestions
{ | ||
$currentSubject = $this->get('subject'); | ||
if (!empty($currentSubject)) { | ||
if (strtolower($currentSubject) !== strtolower($subject)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indention level can 1 less by using &&
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that was a rookie mistake
@@ -75,6 +75,17 @@ public function sendSecondFactorVerificationAuthnRequest( | |||
$originalRequestId = $this->responseContext->getInResponseTo(); | |||
} | |||
|
|||
$subject = $stateHandler->getSubject(); | |||
if (!empty($subject) && strtolower($subjectNameId) !== strtolower($subject)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you did it
*/ | ||
/** @var ResponseValidator */ | ||
private $responseValidator; | ||
|
||
public function __construct( | ||
SamlAuthenticationLogger $samlLogger, | ||
LoaResolutionService $loaResolutionService, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Candidate for constructor property promotion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, when we are upgrading to php8 we surely will do that. For now this code must be PHP72 compat.
@@ -105,6 +102,8 @@ public function respond(ResponseContext $responseContext) | |||
} | |||
|
|||
$secondFactor = $this->secondFactorService->findByUuid($selectedSecondFactorUuid); | |||
$this->responseValidator->validate($request, $secondFactor, $responseContext->getIdentityNameId()); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When do we use an extra empty line, is that personal preference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No hard requirements here. Only to not have a newline between the last closing parenthesis' of a PHP Class
}
}
Yields: ERROR | [x] The closing brace for the class must go on the next line after the body
In this case I wanted to emphasize the validation method.
public function __construct( | ||
SecondFactorTypeService $secondFactorTypeService, | ||
ProviderRepository $providerRepository, | ||
PostBinding $postBinding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Candidate for constructor property promotion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment
*/ | ||
public function validate(Request $request, SecondFactor $secondFactor, string $nameIdFromState) | ||
{ | ||
$secondFactorType = new SecondFactorType($secondFactor->secondFactorType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard coupling, maybe use a factory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is acceptable here. Given it's a (very) simple ValueObject.
8dfe2c1
to
2ea1031
Compare
2ea1031
to
ba05073
Compare
$provider->getRemoteIdentityProvider(), | ||
$provider->getServiceProvider() | ||
); | ||
$nameIdFromResponse = $samlResponse->getNameId()->getValue(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peer review: rename to subjectNameId from response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to: subjectNameIdFromResponse
|
||
use RuntimeException as BaseRuntimeException; | ||
|
||
class RuntimeException extends BaseRuntimeException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peer review feedback: Why not give this a more descriptive name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up renaming this Exception to: ReceivedInvalidSubjectNameIdException
use Surfnet\StepupGateway\SecondFactorOnlyBundle\Exception\RuntimeException; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class ResponseValidator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Peer review feedback: decouple this?
1. To check the preconditions 2. To verify that the Subject NameID matches the SecondFactor Identifier used to start the authentication.
ba05073
to
d20d7d3
Compare
Improve the GSSP response handling. The response is now actually read from the POST vars, to verify the preconditions. In addition we verify if the Subject NameID from the response matches with the one found in the AuthNRequest.