Skip to content

LG-12085 Returns 400 when blank certificate element is passed through assertion#9960

Merged
Sgtpluck merged 2 commits intomainfrom
dmm/catch-validation-errors
Jan 24, 2024
Merged

LG-12085 Returns 400 when blank certificate element is passed through assertion#9960
Sgtpluck merged 2 commits intomainfrom
dmm/catch-validation-errors

Conversation

@Sgtpluck
Copy link
Contributor

🎫 Ticket

LG-12085

🛠 Summary of changes

Adds a validation for whether the assertion has a blank certificate element.

There's probably a better way to do this, but creating a new validation in the SamlRequestValidator felt the cleanest in terms of being able to create an expected error for the user and return an event that tracks what's happening. Suggestions on other ways to do it welcome! Thanks.

changelog: Bug Fixes, SAML Authentication, Returns 400 with error when a blank certificate element is included in the SAML assertion
@Sgtpluck Sgtpluck force-pushed the dmm/catch-validation-errors branch from 6673d43 to 777d3b5 Compare January 23, 2024 19:32
Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Couple minor comments, but LGTM overall 👍

render 'saml_idp/auth/error', status: :bad_request
def validate_and_create_saml_request_object
# this saml_idp method creates the saml_request object used for validations
validate_saml_request
Copy link
Contributor

Choose a reason for hiding this comment

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

Somewhat related to my previous comment and probably out of scope for what we want to address here, but would we want to extract the other "validations" occurring in validate_saml_request to happen within our validator class / "bad request" handling as well? Specifically the valid_saml_request? check and Nokogiri::XML::SyntaxError rescue in that method.

Imagining something like...

def saml_request_validator
  saml_request = Request.from_deflated_request(raw_saml_request, get_params: params)
  if saml_request.valid?
    SamlRequestValidator.new # ...
  else
    SamlRequestValidator.new # ...
  end
rescue SamlIdp::XMLSecurity::SignedDocument::ValidationError
  SamlRequestValidator.new # ...
rescue Nokogiri::XML::SyntaxError
  SamlRequestValidator.new # ...
end

Raising here only in case it would affect how we'd want to approach this generally, such as the snippet above avoiding the before_action altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, long-term we definitely want to extract other validation errors, as well as specific certificate signature errors. (you can see some code i wrote to address that here: 18F/saml_idp#86).

however, there are a lot of unknowns around saml assertion changes (and can really balloon quickly in complexity), and this ticket is fairly tightly scoped to address the 500s that have been occurring regularly, so i do think this suggestion is out of scope of this particular ticket. better errors/clearer code is something i am hoping to have added as part of the protocols team roadmap when it spins up!

Copy link
Contributor

@nprimak nprimak left a comment

Choose a reason for hiding this comment

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

LGTM!

@Sgtpluck Sgtpluck merged commit 6c250bf into main Jan 24, 2024
@Sgtpluck Sgtpluck deleted the dmm/catch-validation-errors branch January 24, 2024 13:01
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