Don't set session[:sp] if no issuer is present#1913
Merged
Conversation
**Why**: For some yet unknown reason, some people are getting in a
state where they have an `sp` key in the session, but with nil values
for issuer and other attributes. The only place we set `session[:sp]`
is in `StoreSpMetadataInSession`, which means that somehow, the
service is being called either with a nil `request_id`, or a
`request_id` that no longer matches one in the DB.
This was causing an exception when the user viewed the agency handoff
page because the view was determining whether or not the user is allowed
to view the page based only on the presence of `session[:sp]`, which is
true in this case, which then calls
`@view_model.service_provider_partial`, which has this logic:
```ruby
def service_provider_partial
if @decorated_session.is_a?(ServiceProviderSessionDecorator)
'sign_up/completions/show_sp'
else
'sign_up/completions/show_identities'
end
end
```
Because there is no issuer in the `sp` hash, the decorated session is a
regular `SessionDecorator`, and so the app tries to render
`sign_up/completions/show_identities`, which has a bug because it's
trying to call a method on the user's `identities` even if the user does
not have any identities:
```slim
- if identities.length > 1
= t('idv.messages.agencies_login')
- else
= t('idv.messages.agency_login_html', sp: identities.first.display_name)
```
**How**:
- Don't set `session[:sp]` if a ServiceProviderRequest cannot be found
- Check for the presence of the issuer in the agency handoff page
- Add logging to help determine where and if the `request_id` is being
dropped or changed.
8 tasks
jmhooper
approved these changes
Jan 16, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why: For some yet unknown reason, some people are getting in a
state where they have an
spkey in the session, but with nil valuesfor issuer and other attributes. The only place we set
session[:sp]is in
StoreSpMetadataInSession, which means that somehow, theservice is being called either with a nil
request_id, or arequest_idthat no longer matches one in the DB.This was causing an exception when the user viewed the agency handoff
page because the view was determining whether or not the user is allowed
to view the page based only on the presence of
session[:sp], which istrue in this case, which then calls
@view_model.service_provider_partial, which has this logic:Because there is no issuer in the
sphash, the decorated session is aregular
SessionDecorator, and so the app tries to rendersign_up/completions/show_identities, which has a bug because it'strying to call a method on the user's
identitieseven if the user doesnot have any identities:
How:
session[:sp]if a ServiceProviderRequest cannot be foundrequest_idis beingdropped or changed.
Hi! Before submitting your PR for review, and/or before merging it, please
go through the following checklist:
For DB changes, check for missing indexes, check to see if the changes
affect other apps (such as the dashboard), make sure the DB columns in the
various environments are properly populated, coordinate with devops, plan
migrations in separate steps.
For route changes, make sure GET requests don't change state or result in
destructive behavior. GET requests should only result in information being
read, not written.
For encryption changes, make sure it is compatible with data that was
encrypted with the old code.
Do not disable Rubocop or Reek offenses unless you are absolutely sure
they are false positives. If you're not sure how to fix the offense, please
ask a teammate.
When reading data, write tests for nil values, empty strings,
and invalid formats.
When calling
redirect_toin a controller, use_url, not_path.When adding user data to the session, use the
user_sessionhelperinstead of the
sessionhelper so the data does not persist beyond the user'ssession.
When adding a new controller that requires the user to be fully
authenticated, make sure to add
before_action :confirm_two_factor_authenticated.