• Resolved Robert

    (@flobbit)


    Environment: PHP 8.3, plugin version 5.4.3. The same code path exists in current builds, only the line numbers differ.

    Summary

    Any POST request carrying a SAMLResponse parameter that base64-decodes to an empty string causes an uncaught ValueError and a fatal 500. We are seeing this at high volume on a production site, driven by automated bot traffic hitting the site root. No real SSO is involved.

    PHP Fatal error: Uncaught ValueError: DOMDocument::loadXML(): Argument #1 ($source) must not be empty in …/miniorange-saml-20-single-sign-on/class-mo-saml-utilities.php

    Steps to reproduce

    Step 1: Install and activate the plugin. No IdP configuration is required.

    Step 2: curl -X POST -d “SAMLResponse=a” https://example.com/

    Step 3: The request returns a 500 and a fatal error is written to the PHP error log.

    Any value that base64-decodes to an empty string reproduces it, for example a, -, % or !!!!

    Cause

    In Mo_SAML_Login_Validate::mo_saml_login_validate(), $_POST[‘SAMLResponse’] is checked with ! empty(), then passed through sanitize_text_field() and base64_decode(). In non-strict mode base64_decode() returns an empty string when the input contains no usable base64 characters. That empty string is then passed to Mo_SAML_Utilities::mo_saml_safe_load_xml(), which calls $document->loadXML( $xml, LIBXML_NONET ).

    On PHP 8, an empty first argument to loadXML() throws a ValueError rather than emitting a warning, so both existing guards miss it.

    First, the set_error_handler() guard (mo_saml_handle_xml_error) never fires, because there is no warning to intercept.

    Second, Mo_Saml_User_Login_Handler::mo_saml_handle_login_validate() cannot catch it, because its final catch block is catch ( Exception $ex ) and ValueError extends Error, not Exception. The error therefore escapes as an uncaught fatal.

    Suggested fix

    Guard the input in mo_saml_safe_load_xml() before calling loadXML(), for example by throwing Mo_SAML_Invalid_XML_Exception when $xml is not a string or trims to an empty string.

    Two related hardening suggestions. Use base64_decode( $saml_response, true ) and bail cleanly when it returns false, so malformed input is rejected before it reaches the XML layer. Also change the final catch ( Exception $ex ) in mo_saml_handle_login_validate() to catch ( Throwable $ex ), so PHP 8 Error and ValueError cases degrade to the existing friendly message rather than a fatal.

    The same empty-input path exists in class-mo-saml-upload-metadata-handler.php, which also passes file contents straight to mo_saml_safe_load_xml().

    One related observation: update_option() stores the raw SAMLResponse before any validation happens, so unauthenticated junk input is written to the options table on every one of these requests.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Ishika Bansal

    (@ishikaatxecurify)

    Hi Robert,

    Thank you for pointing out the issue and bringing it to our attention. We truly appreciate your feedback and the time you took to report it.

    We have identified the issue and will work on fixing it as a priority. We will include the fix in an upcoming release and aim to make it available as soon as possible.

    In the meantime, if you notice anything else or have any additional feedback, please feel free to let us know. We’ll be happy to look into it.

    Thanks & Regards,

    Ishika

    Plugin Support Ishika Bansal

    (@ishikaatxecurify)

    Hi Robert,

    Hope you are doing well!

    I’m happy to let you know that we have fixed the issue related to the empty SAML Response and released the updated plugin version.

    Please update to the latest version at your convenience and let us know if you encounter any issues or need any assistance with the upgrade.

    Thanks,
    Ishika

    Thread Starter Robert

    (@flobbit)

    Brilliant, thank you!

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.