Skip to content

Prevent reused SAML assertions from signing users in - #123

Draft
joehoyle wants to merge 5 commits into
masterfrom
codex/saml-replay-protection
Draft

joehoyle wants to merge 5 commits into
masterfrom
codex/saml-replay-protection

Conversation

@joehoyle

@joehoyle joehoyle commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

A previously accepted signed SAML assertion can currently be submitted again to establish another WordPress login. Claim its ID in the database after response validation and before user provisioning or sign-in, so only one login can use it, including when copies arrive concurrently.

Use the existing options table with autoload disabled and a key derived from the configured IdP and assertion ID. Multisite destinations share the current network's main-site table. Forwarding does not consume the assertion, and a storage failure blocks sign-in.

Strict validation remains unchanged. Replay records are retained indefinitely because deleting a record while expired assertions remain acceptable would allow that assertion to be used again. This prevents reuse after the first accepted login; it does not reject an expired assertion on its first submission. Independent installations do not share replay records.

Validation:

  • Exercised actual plugin functions and the bundled SAML library with synthetic signed responses, minimal WordPress adapters, and an isolated MySQL database.
  • Verified first-use acceptance, subsequent rejection, unchanged assertion IDs in newly signed responses, changed response issuers, missing assertion IDs, signature failures, expired-response reuse, storage failures, and shared multisite storage.
  • Twelve simultaneous submissions produced one accepted login and eleven rejections.
  • PHP syntax and git diff checks passed. Full WordPress/browser cross-site integration testing remains outstanding.

This pull request was opened by AI on Joe's behalf.

Delivers: https://github.com/humanmade/product-dev/issues/2390

Comment thread inc/namespace.php Outdated
}

// Use the configured IdP, rather than an issuer supplied by the response.
$option_name = 'wpsimplesaml_used_assertion_' . hash( 'sha256', $idp['entityId'] . "\0" . $assertion_id );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A NUL character here feels like a potential problem in waiting (I've seen too many hashing null termination bugs), can we use some other sort of separator here?

Comment thread inc/namespace.php Outdated
$previous_suppression = $wpdb->suppress_errors();
try {
$result = $wpdb->query( $wpdb->prepare(
"INSERT IGNORE INTO `$table` (option_name, option_value, autoload) VALUES (%s, %s, %s)",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needs a phpcs ignore here - not that phpcs is great in general on this repo, but let's not make it worse

Use unambiguous length-prefixed keys while atomically retaining legacy claims so existing records and overlapping older workers remain protected. Limit the PHPCS exception to trusted table interpolation and add signed-response, MySQL and concurrency regression coverage.
Configure only the disposable CI MySQL user with the authentication method supported by PHP 7.1, and let both matrix jobs report their results.
Separate fixture execution from WordPress function adapters and scope two exceptions to the MySQL constants required by the disposable database harness.

This branch has not been deployed

No deployments
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