Skip to content

LG-8432: Update SAML ForceAuthn enforcement to track state in SP session object#7616

Merged
julialeague merged 12 commits intomainfrom
jlallen/update-forceauthn-enforcement
Jan 12, 2023
Merged

LG-8432: Update SAML ForceAuthn enforcement to track state in SP session object#7616
julialeague merged 12 commits intomainfrom
jlallen/update-forceauthn-enforcement

Conversation

@julialeague
Copy link
Contributor

@julialeague julialeague commented Jan 11, 2023

🎫 Ticket

https://cm-jira.usa.gov/browse/LG-8432

🛠 Summary of changes

Our recent updates to the SAML internal flow (see #6922) introduced an issue with our enforcement of the ForceAuthn attribute, where users would be stuck in an indefinite sign-out/sign-in loop for service providers passing ForceAuthn=true in their SAMLRequest. This update fixes that by checking whether we're at the final request which will redirect back to the service provider, and skips signing out if so (because the sign-out would have already been enforced before that point in our internal SAML flow). This is also currently behind a feature flag that will eventually be removed once we confirm everything works as expected (covered in another JIRA).

This issue was identified as a part of the rollout of the feature flag saml_internal_post, first introduced in #6922 . We have a related comms plan where we also include the dates for the feature rollout: https://docs.google.com/document/d/159Mjrvmll-4uIKhzSoFEw_3pp20TWSI1f0ZH1Kvtdfc/edit#heading=h.hptnw14jf34z

@julialeague julialeague changed the title Jlallen/update forceauthn enforcement Ensure SAML ForceAuthn attribute is honored while avoiding a sign-out/sign-in loop Jan 11, 2023
@julialeague julialeague changed the title Ensure SAML ForceAuthn attribute is honored while avoiding a sign-out/sign-in loop Update SAML ForceAuthn enforcement to track state in SP session object Jan 11, 2023
Copy link
Contributor

@orenyk orenyk left a comment

Choose a reason for hiding this comment

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

left a few comments/questions, looks good overall!

# for a SAML service provider request to avoid a sign-out/sign-in loop
# when ForceAuthn = true in the SAMLRequest (as handled
# in saml_idp_auth_concern.rb#sign_out_if_forceauthn_is_true_and_user_is_signed_in)
def sp_session_request_url_with_updated_params(final = false)
Copy link
Contributor

Choose a reason for hiding this comment

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

question: is there ever a case where we'd want to call this and not set the sp_session[:final_auth_request] = true? I'm not immediately seeing the need for the method parameter here but I could def be missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this parameter after discussing this more with Oren. I introduced the parameter as a way to protect against a certain edge case, which I wasn't sure needed to be protected. Oren confirmed with me the case I had in mind is not needing to be protected from bypassing ForceAuthn.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

commit where I removed the param: 114280b

end
end

# temporarily commenting out this spec because it needs to be updated to work
Copy link
Contributor

Choose a reason for hiding this comment

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

question: I'm guessing this was meant to be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep! Fixed in 114280b

:validate_saml_request,
:validate_service_provider_and_authn_context,
:store_saml_request,
:store_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.

comment: I think this might violate our linters but I'm not sure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 114280b


# visit from SP with force_authn: true
visit_saml_authn_request_url(overrides: saml_request_overrides)
expect(page.has_content?(
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: I think you can replace this with expect(page).to have_content(...)

Copy link
Contributor Author

@julialeague julialeague Jan 12, 2023

Choose a reason for hiding this comment

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

Great point! Fixed in dae1af3

expect(page.has_content?(
'Test SP is using Login.gov to allow you to sign in to your account safely and securely.'
)).to be true
expect(page.has_button?('Sign in')).to be true
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: similarly, I think this can be expect(page).to have_button('Sign in')

Copy link
Contributor Author

@julialeague julialeague Jan 12, 2023

Choose a reason for hiding this comment

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

Great point again - fixed in dae1af3

@julialeague julialeague changed the title Update SAML ForceAuthn enforcement to track state in SP session object LG-8432: Update SAML ForceAuthn enforcement to track state in SP session object Jan 12, 2023
@julialeague julialeague marked this pull request as ready for review January 12, 2023 01:03
Copy link
Contributor

@orenyk orenyk left a comment

Choose a reason for hiding this comment

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

Looks good to me, nice work!

session.fetch(:sp, {})
end

# Retrieves the current service provider session hash's logged request URL, if present
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: great job adding documentation to a somewhat unintuitive method!

@julialeague julialeague merged commit f16bdbf into main Jan 12, 2023
@julialeague julialeague deleted the jlallen/update-forceauthn-enforcement branch January 12, 2023 20:39
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.

2 participants