Repository navigation
fix(wp-native-auth): browser handoff honors challenge policies and the minting session - #125
Merged
Merged
Conversation
…e minting session Handoff tokens record the device session that minted them. Before the receiver sets a cookie, the first challenge policy that would challenge the user must have verified that session; a revoked session or a policy error refuses the handoff. A generic wp_native_auth_pre_browser_handoff filter can refuse further. Successful handoffs now fire wp_login; refused or invalid ones redirect to wp_login_url() instead of wp_die(). Fixes #124
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.
Fixes #124
A browser handoff can no longer turn a session that skipped a challenge policy into a web session. The receiver now checks the policies and the session that minted the token before it sets a cookie, and fires
wp_loginwhen it does.Change
Mint (
wp_native_auth_create_handoff_token( $user_id, ?string $device_id = null )): the token records the minting device session. It defaults to the current bearer session when that session belongs to the user. Thewp-native/auth-browser-handoffability gets this with no code change. A token minted without a bearer session recordsdevice_id: null.Consume (
wp_native_auth_process_browser_handoff(), called by theinitreceiver), through the newwp_native_auth_check_browser_handoff():handoff_session_inactive.reasonandphaseset tobrowser_handoff. As on login, the first policy that would challenge decides. The minting session must havechallenge_policyequal to that policy and a non-nullchallenge_verified_at. Otherwise:handoff_challenge_required(withdata.challenge_policy). A policyWP_Errorrefuses the handoff.wp_native_auth_pre_browser_handoff(null|WP_Error,WP_User,{device_id, session, challenge_policy}). It runs only after the policies allow the handoff, so it can refuse one but never override a policy refusal.wp_loginwp_login, thenwp_native_auth_after_browser_handoffwp_login_url( $destination )wp_die()403 screenRefusals fire
wp_native_auth_browser_handoff_refused($user_id,WP_Error). The login redirect can be changed withwp_native_auth_browser_handoff_refused_redirect. The destination is now absolute (site origin + request path, minus the handoff param), so login redirects can carry it.Notes for integrations
reason: 'browser_handoff'. A policy should only report whether it would challenge, and should not deliver anything (for example, send a code) for that reason. This is documented in SCHEMAS.md.wp_native_auth_validate_handoff_token()keeps its signature and return value.wp_native_auth_consume_handoff_token()returns the full handoff (user_id,device_id,created_at).wp_loginparity and the redirect on an invalid token. Tokens minted before deploy have nodevice_idand are treated as "no session". The TTL is 60 seconds.Tests
tests/test-browser-handoff-challenge.php(16 tests) mints real tokens from real bearer sessions (password login, optionally continued through a test policy) and consumes them in a signed-out request. It covers each row of the table above, plus: the device is recorded for the bearer's own user only, single use, probe context, policy error, filter can refuse but not allow, filterable refusal redirect, and the destination drops the handoff param.homeboy review test: 163 tests, 162 passed, 1 skipped (pre-existing skip).main: 147 tests, 146 passed, 1 skipped. The +16 are the new tests.homeboy review lint: PHPCS 0 errors (warnings are the existing baseline), PHPStan level 7 clean, no drift.Written directly by Extra Chill Bot (AI agent) for Chris Huber.