Search by

beffroi / saml

Spomkywelcomattic

SAML 2.0 module of the IdP: the profile on top of beffroi/saml2-model and beffroi/saml2-bindings, the identity provider and the service provider of a tenant, their metadata, the attributes mapped from the claims, a NameID derived from the sub, Single Logout on the session of the core. Pure PHP.

Package info

github.com/beffroi-auth/saml

pkg:composer/beffroi/saml

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

0.1.x-dev 2026-11-23 07:32 UTC

This package is auto-updated.

Last update: 2026-11-23 09:05:39 UTC


README

Part of beffroi/framework, developed in src/saml of that monorepo; this repository is its read-only split. Issues and pull requests go to the monorepo.

The SAML 2.0 module of the identity provider: the profile written on beffroi/saml2-model and beffroi/saml2-bindings for the tenants, the users and the sessions of beffroi/core: the identity provider and the service providers of a tenant, their metadata, the attributes mapped from the claims, the NameID derived from the sub, Single Logout on the session of the core. Pure PHP, in the four layers of the identity provider's packages; the HTTP request is the application's.

spec/saml.md is the law of the package: the code conforms to it, or the document changes first. This file is its short version. The package is being built by sub-spike 9c, the identity provider role (beffroi-auth/beffroi#645): it holds the identity provider of a tenant so far, its signing key, kept by the KMS as every key of the tenant, the self-signed certificate around that key and the metadata that publishes it, the next key's certificate beside the current one before it signs anything; and the service providers of the tenant, declared in its configuration, their metadata read from a file or an https URL, trusted by that channel or verified under pinned certificates, refused when expired or older than the document accepted, and refused when they ask for encryption without a key for it; and the signature the authentication requests of a service provider need, required unless its declaration says it does not sign and its metadata do not say it does, whatever the tenant announces, the assertion going only to an assertion consumer service of its accepted metadata; and single sign-on: a request received over HTTP-Redirect or HTTP-POST, answered from the session of the core or after its login, with a response and an assertion both signed by the key of the tenant, valid five minutes, addressed to that request, carrying a persistent NameID of its own per service provider and the attributes its declaration maps from the claims the provider serves, the assertion encrypted for a service provider whose declaration asks for it, to the first key for encryption of its accepted metadata, under AES-GCM and never in CBC, signed before it is encrypted and the response signed over the ciphertext; and Single Logout started by a service provider: a signed LogoutRequest received over either binding, accepted once, ending the sessions of the core it names when their user is the principal of its NameID, as every session of the core ends, and answered with a signed LogoutResponse at a single logout service of the accepted metadata of that service provider, each service provider's part in a session being recorded; and Single Logout started by the identity provider, at the end session endpoint, on the page of the account or for a service provider that asked: once the sessions have ended, every other service provider of them is sent a signed LogoutRequest through the browser, one after the other, its answer read before the next, the chain kept by the provider and played once, the answer to the service provider that asked saying PartialLogout when one of the others did not log out. Sub-spike 9d, the service provider role (beffroi-auth/beffroi#646), adds the service provider of a tenant: an entity ID of its own, never the one of its identity provider, and metadata that announce its requests signed and ask for signed assertions, one assertion consumer service on HTTP-POST and no single logout, under the same SAML key, which either role draws; a role the deployment does not enable serves no metadata. And the identity providers upstream of it, declared in the configuration of the deployment with the e-mail domains each answers for, one provider per domain, and the attributes an assertion of it is read for: their metadata read from a file or an https URL by the objects that read the metadata of a service provider, never expired nor older than the document accepted, and refused without a key for signing or with a single sign-on service that is not https. And the request it sends one of them for an interaction of the browser: written by the model, signed by the key of the tenant, sent to the single sign-on service of the accepted metadata of that provider over HTTP-Redirect, or over HTTP-POST when it offers no other, asking for a fresh login when the client did, its RelayState a random reference to what the browser remembers of it and nothing else. And the key each of them encrypts an assertion for, one per provider, kept by the KMS and rotated as every key of the tenant, never the key of another provider: its certificate is published in metadata of the service provider given to that provider alone, the next one first, and the key the model is given with a provider opens what that provider encrypted and nothing another one did.

The package requires PHP 8.4 or later, beffroi/core, beffroi/saml2-model, beffroi/saml2-bindings, beffroi/xml-security and spomky-labs/pki-framework.

What its code never calls

Section 8 of the specification, enforced in src/ and in tests/ by the PHPStan rules of the monorepo (.ci-tools/phpstan-saml.neon): validateAuthenticatedByBinding(), the binding's authentication being the word of saml2-bindings alone; Closure::bind(), Closure::bindTo() and Closure::call(); Reflection; the unserializer, unserialize() and session_decode(), and the methods unserialize() and __unserialize() on any receiver. Each would let a message received by saml2-bindings be paired with a signature verified over another input. A first-class callable, a callable string or a callable array naming one of them is refused as the call is. Beside them, what the packages below it ban: the DOM and every parser but the loader of xml-security, the weak generators of randomness, and the statements and functions ekino/phpstan-banned-code bans by default (eval, exec(), echo, ...).

Development

From the root of the monorepo, which holds the toolchain of every package:

composer install
castor prepare-pr                                # Mago lint and format, Rector, PHPStan, Deptrac
castor phpstan                                   # this package under .ci-tools/phpstan-saml.neon: level max, no baseline, the bans of section 8
castor phpstan-saml-rules                        # the bans of section 8 proven: one line of the fixture per banned form, compared to what PHPStan reports
castor deptrac                                   # the layers of section 2 and the graph of the packages

Every task runs inside the ghcr.io/spomky-labs/phpqa image when Docker is available.

Security

See the security policy of the monorepo: private reporting, an advisory and a CVE for every fix.

License

MIT, see the LICENSE of the monorepo.