Git Product home page Git Product logo

wp-simple-saml's Introduction

WordPress Simple SAML
Easy to use Single-sign-on ( SSO ) SAML integration plugin for WordPress, with multi-site / multi-network support.
Build status
A Human Made project. Maintained by Shady Sharaf.

WordPress Simple SAML is a flexible, extensible SAML integration plugin, which does most of the grunt work while keeping everything configurable through actions and filters throughout the plugin.

The plugin supports multi-site networks, and cross-network SSO delegation as well. Can be installed on site-level, or on network-level.

WordPress Simple SAML uses OneLogin's PHP-SAML toolkit for SAML API integration.

Getting Set Up

  • Copy the plugin files to your wp-content/plugins directory
  • Activate the plugin
  • Head over to configuration screen.
  • Send Service Provider metadata URL ( or content ) to your Identity Provider authority (IdP) ( find the link in settings page ).

Note: If you're activating the plugin network-wide via code, you might need to use the filter wpsimplesaml_network_activated to override the standard WordPress check, something like this would be what you need:

add_filter( 'wpsimplesaml_network_activated', '__return_true' )

Configuration

There is two ways to configure the plugin, either from the admin interface or using filters, both can be used interchangably as the project requires, usually filters prevail database settings though.

Admin configurations

Depending on whether the plugin is network-activated or not, you will need to go to Settings \ General or Network Settings pages.

  • SSO Status is how the plugin integrates with WordPress login process, available options are Disable, Display login link which only provides a link in the login form, Force redirect which overrides the login form altogether and directly goes to SSO login page.
  • SSO Base URL (optional) is the home URL of the WordPress site that serves as the delegate ( main service provider ) to which SAML responses will be posted, usually this is the main site of the network, and is the same value for siteurl option, eg https://my.site/
  • SSO IdP Metadata (required, if not filtered) Copy of the SSO IdP metadata XML file, which can also be passed via either wpsimplesaml_idp_metadata_xml_path for a path to the XML file, or wpsimplesaml_idp_metadata_xml for the contents of the XML, or wpsimplesaml_idp_metadata for the configuration array.
  • SSO delegation whitelisted hosts List of hosts to whitelist during delegation of SAML responses, ie: secondary domains that needs to use SSO as well from the same IdP. Local sites are allowed by default.
  • SSO Role Management Enables developers to assign different roles to users based on SAML Responses, disabled by default, and is controlled via a few filters,
  • SSO Debug via Cookies Allows developers to use a special cookie named sso_debug to override the SSO Status option during testing. Possible value of the cookie are force and link, which are self-explanatory.
  • SSO Config validation Shows information about IdP metadata and validity of its settings.

Configuration via code

WordPress Simple SAML is built to be as extensible as possible, so most aspects of the login/validation process can be tweaked as needed by using the available well-documented Hooks.

TL;DR; This is the basic minimum filters you'd need to get an implementation working with the default options.

// SAML metadata XML file path
add_filter( 'wpsimplesaml_idp_metadata_xml_path', function(){
	return ABSPATH . '/.private/sso/test.idp.xml';
} );

// Configure attribute mapping between WordPress and SSO IdP SAML attributes
add_filter( 'wpsimplesaml_attribute_mapping', function(){
	return [
		'user_login' => 'uid',
		'user_email' => 'email',
	];
} );

Testing

As SSO authorities are usually a pain to change, and credentials take time to be configured, we've documented steps to get a sample SAML IdP ( Identity provider ) up and running using a test docker container. See more at Testing SSO Locally.

Contribute

First, thanks for contributing!

Setting up

To get development dependencies, install composer and npm dependencies via:

composer install
npm install

This installs Human made's version of WordPress Coding Standards via PHP Code Sniffer, and symlinks a precommit hook to automatically check all commits for code quality concerns.

Workflow

  • Find an issue you'd like to help with, or create a new one for the change you'd like to introduce.
  • Fork the repo to your own account
  • Issue pull-requests from your fork to ours
  • Tag the issue you're trying to resolve in your pull-request for some context
  • Make sure the pull-request passed all Travis checks
  • Tag any of the contributors for a review.

Next

Check issues list for what's planned next.

Credits

Created by Human Made for network-wide SAML SSO Integrations, because of the lack of a well-written WordPress integration with the features/flexibility our clients require.

Written and maintained by Shady Sharaf. Thanks to all our contributors.

Interested in joining in on the fun? Join us, and become human!

Changelog

  • 0.3

    • Fix compatibilty with WordPress single site (no multisite).
    • Fix error caused by using WordPress dashboard function outside the dashboard.
  • 0.2.1

    • Fix missing composer dependency and updated .gitignore
  • 0.2

    • Updating PHP SAML library to 3.0 to support PHP 7.x
  • 0.1

    • Stable version

wp-simple-saml's People

Contributors

askvortsov1 avatar dependabot[bot] avatar faishal avatar gazi96 avatar gonzomir avatar joehoyle avatar johnbillion avatar mikelittle avatar mikeselander avatar paulgibbs avatar rmccue avatar roborourke avatar shadyvb avatar tfrommen avatar tinder-kyleboss avatar tomjn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-simple-saml's Issues

Backdoor link

Add a backdoor link (ie /?saml_sso=false) that will allow the Forced Redirect to be disabled.

Open-source this repo

@shadyvb Is there anything stopping us from open sourcing this repo? :) Happy to write up the readme/etc if you don't have time.

SSO Config validation causes fatal error before metadata is saved

In an environment with the plugin network enabled, entering the network settings page to provide the SSO IdP Metadata provides a broken settings page, as the SSO Config validation field expects the metadata to exist already when viewing the page.

The outcome of this is that it is impossible to save the page, so you are unable to add the metadata to resolve the issue without manually adding the sso_idp_metadata meta key and value to the wp_sitemeta database.

Improve Composer file and Release on Packagist

While I can currently include this plugin using Composer installers, it would be really nice to be able to include it as a first-class Composer dependency.

Will likely follow this up with a PR soon.

Upgrade PHP-SAML to v3.0

The PHP-SAML library currently uses the mcrypt library that was deprecated in PHP 7.1. This means that this plugin can't be used on WordPress VIP or, really, any modern web host.

PHP-SAML has a 3.0 version which will could change some of the integration, but allows the plugin to be usable on modern hosts. It is not officially tagged, however it can be tagged with 3.0.0.x-dev to at least prepare for the change.

Reference: SAML-Toolkits/php-saml#255

Make it easier to debug SAML errors

Recently I had to debug SSO errors where users were seeing 500 errors because of some infra configuration errors, but debugging this was very difficult as I had to figure out and spend some time to get some logging setup.

The way I did was to add logging into X-ray with more details for the error from $saml->getLastErrorReason() and $saml->getLastErrorException()

function get_sso_user() {
$saml = instance();
try {
$saml->processResponse();
} catch ( \Exception $e ) {
/* translators: %s = error message */
return new \WP_Error( 'invalid-saml', sprintf( esc_html__( 'Error: Could not parse the authentication response, please forward this error to your administrator: "%s"', 'wp-simple-saml' ), esc_html( $e->getMessage() ) ) );
}
if ( ! empty( $saml->getErrors() ) ) {
$errors = implode( ', ', $saml->getErrors() );
/* translators: %s = error message */
return new \WP_Error( 'invalid-saml', sprintf( esc_html__( 'Error: Could not parse the authentication response, please forward this error to your administrator: "%s"', 'wp-simple-saml' ), esc_html( $errors ) ) );
}
if ( ! $saml->isAuthenticated() ) {
return new \WP_Error( 'not-authenticated', esc_html__( 'Error: Authentication wasn\'t completed successfully.', 'wp-simple-saml' ) );
}
return get_or_create_wp_user( $saml );
}

I am thinking about how we can make it easier to debug this, One of the simplest solutions I am thinking of is to also trigger WordPress actions with related information and let the application code handle different logging?

It breaks when adding XML medatata to SSO IdP Metadata

I created a WP sandbox to implement SSO. When I add the XML medadata to the SSO Ido Metadata field I get the following error:

Invalid array settings: sp_entityId_not_found, sp_acs_url_invalid, sp_sls_url_invalid

Screen Shot 2020-03-09 at 4 05 47 PM

Here is the format of the XML I add to the field:

<?xml version="1.0"?>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" validUntil="XXXXXXX" cacheDuration="XXXXXX" entityID="XXXXX">
  <md:IDPSSODescriptor WantAuthnRequestsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
    <md:KeyDescriptor use="signing">
      <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <ds:X509Data>
          <ds:X509Certificate>XXXXXXXXXXXXXXXXXXX=</ds:X509Certificate>
        </ds:X509Data>
      </ds:KeyInfo>
    </md:KeyDescriptor>
    <md:KeyDescriptor use="encryption">
      <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
        <ds:X509Data>
          <ds:X509Certificate>XXXXXXXXXXXX=</ds:X509Certificate>
        </ds:X509Data>
      </ds:KeyInfo>
    </md:KeyDescriptor>
    <md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
    <md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://fidm.us1.gigya.com/saml/v2.0/XXXXXXXXXXXXXXXXXXX/idp/metadata"/>
  </md:IDPSSODescriptor>
</md:EntityDescriptor>

Deprecated: Function libxml_disable_entity_loader()

On the Options page: https://mysite.com/wp-admin/options-general.php I see the following deprecated notice twice:

Deprecated: Function libxml_disable_entity_loader() is deprecated in /srv/www/wp-content/plugins/wp-simple-saml/vendor/onelogin/php-saml/src/Saml2/Utils.php on line 89

Deprecated: Function libxml_disable_entity_loader() is deprecated in /srv/www/wp-content/plugins/wp-simple-saml/vendor/onelogin/php-saml/src/Saml2/Utils.php on line 91

Recently updated the environment to php 8.0, WP version 5.7.6

Call to undefined function HumanMade\SimpleSaml\is_plugin_active_for_network() on multisite

Enabling it on a multisite servers gives the following error:
Fatal error: Uncaught Error: Call to undefined function HumanMade\SimpleSaml\is_plugin_active_for_network() in /var/www/html/wordpress/wp-content/plugins/wp-simple-saml/inc/namespace.php:682 Stack trace: #0 /var/www/html/wordpress/wp-content/plugins/wp-simple-saml/inc/admin/namespace.php(140): HumanMade\SimpleSaml\is_sso_enabled_network_wide() #1 /var/www/html/wordpress/wp-content/plugins/wp-simple-saml/inc/admin/namespace.php(370): HumanMade\SimpleSaml\Admin\get_sso_settings('sso_debug') #2 /var/www/html/wordpress/wp-includes/class-wp-hook.php(286): HumanMade\SimpleSaml\Admin\filter_forced_sso(false) #3 /var/www/html/wordpress/wp-includes/plugin.php(203): WP_Hook->apply_filters(false, Array) #4 /var/www/html/wordpress/wp-content/plugins/wp-simple-saml/inc/namespace.php(150): apply_filters('wpsimplesaml_fo...', false) #5 /var/www/html/wordpress/wp-includes/class-wp-hook.php(288): HumanMade\SimpleSaml\authenticate_with_sso(NULL) #6 /var/www/html/wordpress/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array in /var/www/html/wordpress/wp-content/plugins/wp-simple-saml/inc/namespace.php on line 682

This can be fixed by including ABSPATH . '/wp-admin/includes/plugin.php'.

This is documented in:
https://codex.wordpress.org/Function_Reference/is_plugin_active_for_network

Adding the piece of code above it fixed the issue for me.

Cannot force SSO with filter

I may be doing something wrong, but I cannot seem to force the SSO route with the wpsimplesaml_force filter.

I'm trying with this:
add_filter('wpsimplesaml_force', '__return_true');

But I'm still hitting the WP login screen.
If I change the SSO Status to "Force Redirect" it works fine.

Handle nameids that don't validate as emails

Some IdPs might not be configured to send the email in the NameID field, even if the users log in using the email.

We changed our IdP to send the information in the NameID field, but it might be useful for others.

Configuration via code not generating expected SP Metadata

I'm currently trying to use the Configuration via code settings to generated valid SP Metadata. I'm trying to get a similar SP Metadata to the one below:

<?xml version="1.0" encoding="UTF-8"?>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" ID="XXXXXXXXX.doitt.nycnet-console"
entityID="XXXXXXXXX.doitt.nycnet-console"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="#XXXXXXXXX.doitt.nycnet-console"><ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>XXXXXXXXXXXXXXXXXX</ds:DigestValue></ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>XXXXXXXXXXXXXX</ds:SignatureValue>
<ds:KeyInfo>
<ds:X509Data><ds:X509Certificate>XXXXXXXXXXXXXXXXXXXX</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
<md:SPSSODescriptor AuthnRequestsSigned="true" WantAssertionsSigned="true" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:KeyDescriptor use="signing"><ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:X509Data><ds:X509Certificate>XXXXXXXXXXXXXXXXXX</ds:X509Certificate></ds:X509Data></ds:KeyInfo></md:KeyDescriptor>
<md:KeyDescriptor use="encryption"><ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:X509Data>
<ds:X509Certificate>XXXXXXXXXXXXXXXXX</ds:X509Certificate></ds:X509Data></ds:KeyInfo>
</md:KeyDescriptor>
<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="http://XXXXXXXXX.doitt.nycnet/console/saml/SingleLogout/alias/xxxxxx.doitt.nycnet-console"/>
<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="http://XXXXXXXXX.doitt.nycnet/console/saml/SingleLogout/alias/xxxxxx.doitt.nycnet-console"/>
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress</md:NameIDFormat>
<md:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</md:NameIDFormat>
<md:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent</md:NameIDFormat>
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified</md:NameIDFormat>
<md:NameIDFormat>urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName</md:NameIDFormat>
<md:AssertionConsumerService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="http://XXXXXXXXX.doitt.nycnet/console/saml/SSO/alias/xxxxxx.doitt.nycnet-console" index="0" isDefault="true"/>
</md:SPSSODescriptor></md:EntityDescriptor>

To achieve this I try to add the missing fields that were not being generated in the SP Metadata via the code configuration were I tried the following:

/**

  • SIMPLE SAML PLUGIN CONFIGURATION
    */
    add_filter( 'wpsimplesaml_idp_metadata_xml_path', function(){
    return ABSPATH . '.private/sso/test.idp.xml';
    } );
add_filter( 'wpsimplesaml_config', function(){
        return  [
                'entityId'                 => 'https://example.com',
                'assertionConsumerService' => [
                        'url' => 'https://example.com/sso/verify',
                        'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'
                ],
                'singleLogoutService'      => [
                        'url' => 'https:/example.com/sso/sls',
                        'binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST'
                ],
                'AuthNRequest'       => true,
                'signatureAlgorithm' => 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',
                'NameIDFormat'       => 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'
                
        ];
} );

However, the SP Metadata does not change and the above fields such as 'NameIDFormat' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' stay the same as default. No change to the SP Metadata is made. What is the hook to configure the fields expected to be in the SP Metadata required by the idP? Can you provide some guidance please.

SSO base url redirect to root

I'm currently trying to implement SSO into a wordpress application. I'm using wp-simple-saml, when I click on the SSO login link I'm not being redirected to the SSO idP. I have added the end point to where the redirection of the SSO base url endpoint. However, redirection sends me back to root.

Warning thrown from XML Loading

It appears that we're passing an empty string if there is no XML file to pass to the PHP-SAML library. This is spilling PHP warnings.

Stack trace:

[13-Jul-2018 23:26:38 UTC] PHP Warning:  DOMDocument::loadXML(): Empty string supplied as input in /vagrant/content/plugins/wp-simple-saml/vendor/onelogin/php-saml/lib/Saml2/Utils.php on line 88
[13-Jul-2018 23:26:38 UTC] PHP Stack trace:
[13-Jul-2018 23:26:38 UTC] PHP   1. {main}() /vagrant/wp/wp-admin/options-general.php:0
[13-Jul-2018 23:26:38 UTC] PHP   2. do_settings_sections() /vagrant/wp/wp-admin/options-general.php:382
[13-Jul-2018 23:26:38 UTC] PHP   3. do_settings_fields() /vagrant/wp/wp-admin/includes/template.php:1337
[13-Jul-2018 23:26:38 UTC] PHP   4. HumanMade\SimpleSaml\Admin\{closure}() /vagrant/wp/wp-admin/includes/template.php:1378
[13-Jul-2018 23:26:38 UTC] PHP   5. HumanMade\SimpleSaml\instance() /vagrant/content/plugins/wp-simple-saml/inc/admin/namespace.php:268
[13-Jul-2018 23:26:38 UTC] PHP   6. apply_filters() /vagrant/content/plugins/wp-simple-saml/inc/namespace.php:191
[13-Jul-2018 23:26:38 UTC] PHP   7. WP_Hook->apply_filters() /vagrant/wp/wp-includes/plugin.php:203
[13-Jul-2018 23:26:38 UTC] PHP   8. HumanMade\SimpleSaml\Admin\get_config() /vagrant/wp/wp-includes/class-wp-hook.php:286
[13-Jul-2018 23:26:38 UTC] PHP   9. OneLogin_Saml2_IdPMetadataParser::parseXML() /vagrant/content/plugins/wp-simple-saml/inc/admin/namespace.php:57
[13-Jul-2018 23:26:38 UTC] PHP  10. OneLogin_Saml2_Utils::loadXML() /vagrant/content/plugins/wp-simple-saml/vendor/onelogin/php-saml/lib/Saml2/IdPMetadataParser.php:98
[13-Jul-2018 23:26:38 UTC] PHP  11. DOMDocument->loadXML() /vagrant/content/plugins/wp-simple-saml/vendor/onelogin/php-saml/lib/Saml2/Utils.php:88

Use case questions

A few questions to assist in implementation:-

  1. Why is the SP metadata generated with only a 48 hour validity timestamp, this does not appear to be a local limit?
  2. How to automate IDP certificate change updates?
  3. What precisely does wpsimplesaml_cross_sso_form_inputs do & are there examples of implementation.

Also if I may ask, why is this excellent plugin not available through wordpress.org?

404 returned when attempting to reach /sso/verify

Hi there,

Seem to hitting a brick wall with the configuration. I have had the same configuration running locally however when it's extended to the web, i receive a 404 after login to okta ( that parts working fine. )

My question is the issue perhaps related to my using a url like https://www.example.com/**radio**

im running my config programatically... app is activated and i see no issues especially as as said, i've run the configuration locally the only difference really being the url..

Any thoughts on this?

Steve

PHP Fatal error: Call to undefined function HumanMade\SimpleSaml\get_site_by_path()

[23-Nov-2018 00:17:43] WARNING: [pool www] child 8 said into stderr: "NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function HumanMade\SimpleSaml\get_site_by_path() in /var/www/sites/theshire.space/wp-content/plugins/wp-simple-saml-master/inc/namespace.php:622"
172.18.0.5 -  23/Nov/2018:00:17:43 +0000 "POST /index.php" 500
[23-Nov-2018 00:17:43] WARNING: [pool www] child 8 said into stderr: "Stack trace:"
[23-Nov-2018 00:17:43] WARNING: [pool www] child 8 said into stderr: "#0 /var/www/sites/theshire.space/wp-content/plugins/wp-simple-saml-master/inc/namespace.php(212): HumanMade\SimpleSaml\get_blog_id('https://shire.v...')"
[23-Nov-2018 00:17:43] WARNING: [pool www] child 8 said into stderr: "#1 /var/www/sites/theshire.space/wp-includes/class-wp-hook.php(286): HumanMade\SimpleSaml\cross_site_sso('')"
[23-Nov-2018 00:17:43] WARNING: [pool www] child 8 said into stderr: "#2 /var/www/sites/theshire.space/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array)"
[23-Nov-2018 00:17:43] WARNING: [pool www] child 8 said into stderr: "#3 /var/www/sites/theshire.space/wp-includes/plugin.php(453): WP_Hook->do_action(Array)"
[23-Nov-2018 00:17:43] WARNING: [pool www] child 8 said into stderr: "#4 /var/www/sites/theshire.space/wp-content/plugins/wp-simple-saml-master/inc/namespace.php(98): do_action('wpsimplesaml_ac...')"
[23-Nov-2018 00:17:43] WARNING: [pool www] child 8 said into stderr: "#5 /var/www/sites/theshire.space/wp-includes/class-wp-hook.php(286): HumanMade\SimpleSaml\endpoint('')"
[23-Nov-2018 00:17:43] WARNING: [pool www] child 8 said into stderr: "#6 /var/www/sites/theshire.space/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(false, Array..."

Seems similar in issue to #15 where a wordpress function is not included properly.
https://developer.wordpress.org/reference/functions/get_site_by_path/

Because it's from multisite (ms-load.php), it won't work properly in singlesite.

Since two functions are called as actions and it's expected that one should fail,

	add_action( 'wpsimplesaml_action_login', __NAMESPACE__ . '\\cross_site_sso' );
	add_action( 'wpsimplesaml_action_verify', __NAMESPACE__ . '\\cross_site_sso' );
	add_action( 'wpsimplesaml_action_login', __NAMESPACE__ . '\\action_login' );
	add_action( 'wpsimplesaml_action_verify', __NAMESPACE__ . '\\action_verify' );

it would be prudent to modify

function cross_site_sso() {
$redirect_url = get_redirection_url();
if ( isset( $_POST['SAMLResponse'] ) && ( get_current_blog_id() !== get_blog_id( $redirect_url ) ) ) { // @codingStandardsIgnoreLine
cross_site_sso_redirect( $redirect_url );
}
}

function get_blog_id( $url ) {
$fragments = wp_parse_url( $url );
if ( empty( $fragments ) || empty( $fragments['host'] ) ) {
return 0;
}
$site = get_site_by_path( $fragments['host'], $fragments['path'] );
$blog_id = 0;
if ( $site ) {
$blog_id = $site->blog_id;
}
return absint( $blog_id );
}

to not use get_site_by_path().

As is, a quick fix would be to do as @guequierre suggests and do a hard include:

include( ABSPATH . '/wp-includes/ms-load.php' );

However, that also fails since ms-load.php needs other functions inherent in multisite.

Added this to get_blog_id() but this resulted in an infinite redirect loop.

        if ( ! is_multisite() ) {
                return 0;
        }

Not sure what's going on other than it has to do with the site being a sub-domain.

Update: With the above addition of returning 0 on multisite and clearing out the 'SSO delegation whitelisted hosts' box, the function now works and my test user can log in. However, deleting the user in wordpress will cause an error that the site is not present in whitelisted sites.

Post Update: Maybe I was confused on how blogIDs work and that they start at 0.
Using:

        if ( ! is_multisite() ) {
                return 1;
        }

Works and creates users correctly.

Cache SP metadata to avoid per-page hits

  • We need to cache the contents of the XML so we don't hit it on each page load.
  • There should be a way to refresh the cache, using UI or CLI.
  • May use filemtime or detect changes to the XML file and refresh cache.
  • Lazy load the metadata file?

all sso/* paths lead to 404

I have successfully been able to set-up wp-simple-saml on several projects; however, I have a particular project where wp-simple-saml 404's on all sso routes (e.g. sso/login, sso/verify, & sso/metadata). Is there something that might be blocking the creation of these URLs?

Thank you so much!

Compatibility with Flask SAML2 custom IdP

Hi, I need some help with the plugin.
I've installed and configured the plugin via the admin panel so that it should work with my custom IdP I made with the Flask SAML2 Library for Python.

When I click the link for SAML Login on my WordPress website it redirects me to my custom IdP and the authorization process is successful. Then it redirects me back to my WordPress site where a new user is created with the email it got from the IdP but as value for the username instead of the email field (see screenshot below).

wordpress_users

In the following screenshot you can see a SAML packet i have captured with a Firefox extension. -> In the NameID field is the email of my IdP's user database so that works correct.

saml_packet

In this example I replaced my WordPress website link with https://test.com.

When I logout of the WordPress website and try to login again there is the following error message.

wordpress_error_message

Then I had some research and found a similar issue here on GitHub and tried the code mentioned there but it didn't work for me.


So that's what I want to achieve:

  • I have this custom IdP with a database where some users are stored in. (e.g. username: simon, email: [email protected] | username: tim, email: [email protected])
  • Now I want that the user simon has access to the admin account of my WordPress website but the user tim shouldn't have access to and no account should be created when the user tim tries to access the page via SAML authentication.

I found the hook wpsimple_match_user in the documentation but I don't exactly know how I have to implement that code in the plugin.php file so that it works fine.

And the second thing I already tried is the following code but I think the syntax is somehow not correct.

//Disable adding users to site
add_filter( 'wpsimplesaml_add_users_to_site', function(){
    return false;
} );

Thanks for your help

SSO Config validation

Warning: DOMDocument::loadXML(): Start tag expected, '<' not found in Entity, line: 1 in C:\Users\Salim Hachemaoui\Local Sites\wei\app\public\wp-content\plugins\wp-simple-saml\vendor\onelogin\php-saml\src\Saml2\Utils.php on line 90

XML Path: No
XML: Yes
Passed config: No
Valid config: Invalid IdP XML metadata
Errors: No
SP Metadata: http://localhost:10011/sso/metadata

Cross site SSO does not work when using subdomains

When using wp-simple-saml on multisite with subdomains, the plugins appears to be not working. This is due to how the cross-site sso redirect / forwarding works. With the scanario:

  1. Assuming sso_sp_base is your main site url, like https://hmn.md/.
  2. Try to login to updates.hmn.md, correctly you are passed to the SAML provider for auth
  3. The SAML Idp will redirect back to your acs url (https://hmn.md/sso/verify)
  4. wp-simple-saml will see the $redirect_url is from another site, so will do the cross-site sso hop, to re-POST the data to https://updates.hmn.md/sso/verify
  5. On this request, wp-simple-saml will attempt to have onelogin $saml->processResponse(), which will fail, due to the current URL hostname not matching the Destination in the SAML XML response.

I.e. it's not possible to process a SAMLResponse payload on a hostname that doesn't match the Destination field in the SAML app registered in the Idp.

I'm not sure how this was meant to work. I think for this to work, there are two possible approaches:

  1. Process the verify request at the main site, even when they are for sub-sites, so you essentially switch_to_blog() at https://hmn.md/sso/verify and create the user on the site of $redirect_uri (and the same for /login).
  2. Change the behaviour of onelogin somehow to skip validation, or validate it against sso_sp_base rather than the current URL more likely.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.