Skip to content

Commit dc0045e

Browse files
authored
Merge pull request #128 from workivate/CPS-175_upstream_4.1_merge
CPS-175 merge of upstream repository - 4.1.0
2 parents 5615c61 + abbd534 commit dc0045e

25 files changed

+1601
-1774
lines changed

.github/workflows/php-package.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This workflow will install PHP dependencies, run tests and lint with a variety of PHP versions
2+
# For more information see: https://github.com/marketplace/actions/setup-php-action
3+
4+
name: php-saml 4.x package
5+
6+
on:
7+
push:
8+
branches: [ 4.* ]
9+
pull_request:
10+
branches: [ 4.* ]
11+
12+
jobs:
13+
test:
14+
runs-on: ${{ matrix.operating-system }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
operating-system: ['ubuntu-latest']
19+
php-versions: [7.3, 7.4, 8.0, 8.1]
20+
steps:
21+
- name: Setup PHP, with composer and extensions
22+
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
23+
with:
24+
php-version: ${{ matrix.php-versions }}
25+
extensions: mbstring, intl, mcrypt, xml
26+
tools: composer:v2
27+
ini-values: post_max_size=256M, max_execution_time=180
28+
coverage: xdebug
29+
30+
- name: Set git to use LF
31+
run: |
32+
git config --global core.autocrlf false
33+
git config --global core.eol lf
34+
- uses: actions/checkout@v2
35+
36+
- name: Validate composer.json and composer.lock
37+
run: composer validate
38+
39+
- name: Install Composer dependencies
40+
run: |
41+
composer self-update
42+
composer install --prefer-source --no-interaction
43+
- name: Syntax check PHP
44+
run: |
45+
php vendor/bin/phpcpd --exclude tests --exclude vendor .
46+
php vendor/bin/phploc src/.
47+
mkdir -p tests/build/dependences
48+
php vendor/bin/pdepend --summary-xml=tests/build/logs/dependence-summary.xml --jdepend-chart=tests/build/dependences/jdepend.svg --overview-pyramid=tests/build/dependences/pyramid.svg src/.
49+
50+
- name: PHP Code Sniffer
51+
run: php vendor/bin/phpcs --standard=tests/ZendModStandard src/Saml2 demo1 demo2 endpoints tests/src
52+
53+
- name: Run unit tests
54+
run: vendor/bin/phpunit --verbose --debug

README.md

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
1+
# LifeWorks fork of SAML PHP
2+
This repository is a fork from OneLogin's php-saml repository (see below)
3+
4+
It appears that the Master branch of the upstream repository is not how releases are managed, but in the Lifeworks repository we maintain the normal process of feature branch -> Develop -> Master for releases.
5+
6+
Version
7+
-------
8+
2022-08-22 : As part of the preparation for upgrading all PHP code bases to PHP 8.1 (and specifically wa-sso) this package has been synced with the latest changes from the upstream branch, tag version 4.1.0
9+
10+
Notes
11+
-----
12+
As at August 2022, the upstream is not considered to be under active development
13+
14+
https://github.com/onelogin/php-saml/issues/531
15+
16+
In order to make the PHPUnit tests pass, a number of changes that are maintained in the LifeWork Develop branch have been included.
17+
18+
Unit Testing and Static Analysis
19+
--------------------------------
20+
There is no Docker container for this package so PHPUnit and PHPStan must be run from the local development environment.
21+
22+
PHP 8.1 is required
23+
24+
####PHPUnit
25+
Runs the unit tests. This includes the changes maintained within the LifeWorks Repository
26+
```
27+
./vendor/bin/phpunit
28+
```
29+
30+
####PHPStan
31+
PHPStan has been added as part of the PHP 8.1 and Tag 4.1 upgrade work.
32+
```
33+
./vendor/bin/phpstan analyse --memory-limit=-1 -c phpstan.neon
34+
```
35+
36+
Usage
37+
-----
38+
Unlike most other php packages which have been added to the Lifeworks GemFury repository, php-saml was being included directly from the GitHub repository. With this upgrade, the package will be added to GemFury to bring it inline with LifeWorks best practices.
39+
40+
GemFury is the preferred package repository as it works for both local development and also for the CI/CD pipelines.
41+
42+
A ssuch, please remember to do the following when any changes are made.
43+
44+
Update the version in composer.json
45+
Create a new tag and release in Github that matches the new version
46+
Manually download the resulting release ZIP file and upload it to the Lifeworks GemFury account
47+
Run Composer
48+
49+
composer require "workivate/php-saml":"^4.1"
50+
151
# OneLogin's SAML PHP Toolkit Compatible with PHP 7.X & 8.X
252

353
[![Build Status](https://api.travis-ci.org/onelogin/php-saml.png?branch=master)](http://travis-ci.org/onelogin/php-saml) [![Coverage Status](https://coveralls.io/repos/onelogin/php-saml/badge.png)](https://coveralls.io/r/onelogin/php-saml) [![License](https://poser.pugx.org/onelogin/php-saml/license.png)](https://packagist.org/packages/onelogin/php-saml)
@@ -148,6 +198,37 @@ environment is not secure and will be exposed to attacks.
148198

149199
In production also we highly recommended to register on the settings the IdP certificate instead of using the fingerprint method. The fingerprint, is a hash, so at the end is open to a collision attack that can end on a signature validation bypass. Other SAML toolkits deprecated that mechanism, we maintain it for compatibility and also to be used on test environment.
150200

201+
202+
### Avoiding Open Redirect attacks ###
203+
204+
Some implementations uses the RelayState parameter as a way to control the flow when SSO and SLO succeeded. So basically the
205+
user is redirected to the value of the RelayState.
206+
207+
If you are using Signature Validation on the HTTP-Redirect binding, you will have the RelayState value integrity covered, otherwise, and
208+
on HTTP-POST binding, you can't trust the RelayState so before
209+
executing the validation, you need to verify that its value belong
210+
a trusted and expected URL.
211+
212+
Read more about Open Redirect [CWE-601](https://cwe.mitre.org/data/definitions/601.html).
213+
214+
215+
### Avoiding Reply attacks ###
216+
217+
A reply attack is basically try to reuse an intercepted valid SAML Message in order to impersonate a SAML action (SSO or SLO).
218+
219+
SAML Messages have a limited timelife (NotBefore, NotOnOrAfter) that
220+
make harder this kind of attacks, but they are still possible.
221+
222+
In order to avoid them, the SP can keep a list of SAML Messages or Assertion IDs alredy valdidated and processed. Those values only need
223+
to be stored the amount of time of the SAML Message life time, so
224+
we don't need to store all processed message/assertion Ids, but the most recent ones.
225+
226+
The OneLogin_Saml2_Auth class contains the [getLastRequestID](https://github.com/onelogin/php-saml/blob/b8214b74dd72960fa6aa88ab454667c64cea935c/src/Saml2/Auth.php#L657), [getLastMessageId](https://github.com/onelogin/php-saml/blob/b8214b74dd72960fa6aa88ab454667c64cea935c/src/Saml2/Auth.php#L762) and [getLastAssertionId](https://github.com/onelogin/php-saml/blob/b8214b74dd72960fa6aa88ab454667c64cea935c/src/Saml2/Auth.php#L770) methods to retrieve the IDs
227+
228+
Checking that the ID of the current Message/Assertion does not exists in the list of the ones already processed will prevent reply
229+
attacks.
230+
231+
151232
Getting started
152233
---------------
153234

@@ -754,6 +835,8 @@ $_SESSION['samlNameidSPNameQualifier'] = $auth->getNameIdSPNameQualifier();
754835
$_SESSION['samlSessionIndex'] = $auth->getSessionIndex();
755836

756837
if (isset($_POST['RelayState']) && OneLogin\Saml2\Utils::getSelfURL() != $_POST['RelayState']) {
838+
// To avoid 'Open Redirect' attacks, before execute the
839+
// redirection confirm the value of $_POST['RelayState'] is a // trusted URL.
757840
$auth->redirectTo($_POST['RelayState']);
758841
}
759842

@@ -1092,6 +1175,8 @@ if (isset($_GET['sso'])) { // SSO action. Will send an AuthNRequest to the I
10921175

10931176
$_SESSION['samlUserdata'] = $auth->getAttributes(); // Retrieves user data
10941177
if (isset($_POST['RelayState']) && OneLogin\Saml2\Utils::getSelfURL() != $_POST['RelayState']) {
1178+
// To avoid 'Open Redirect' attacks, before execute the
1179+
// redirection confirm the value of $_POST['RelayState'] is a // trusted URL.
10951180
$auth->redirectTo($_POST['RelayState']); // Redirect if there is a
10961181
} // relayState set
10971182
} else if (isset($_GET['sls'])) { // Single Logout Service
@@ -1100,7 +1185,7 @@ if (isset($_GET['sso'])) { // SSO action. Will send an AuthNRequest to the I
11001185
if (empty($errors)) {
11011186
echo '<p>Sucessfully logged out</p>';
11021187
} else {
1103-
echo '<p>' . implode(', ', $errors) . '</p>';
1188+
echo '<p>' . htmlentities(implode(', ', $errors)) . '</p>';
11041189
}
11051190
}
11061191

@@ -1384,6 +1469,8 @@ Auxiliary class that contains several methods to retrieve and process IdP metada
13841469
* `parseXML` - Get IdP Metadata Info from XML.
13851470
* `injectIntoSettings` - Inject metadata info into php-saml settings array.
13861471

1472+
The class does not validate in any way the URL that is introduced on methods like parseRemoteXML in order to retrieve the remove XML. Usually is the same administrator that handles the Service Provider the ones that set the URL that should belong to a trusted third-party IdP.
1473+
But there are other scenarios, like a SAAS app where the administrator of the app delegates on other administrators. In such case, extra protection should be taken in order to validate such URL inputs and avoid attacks like SSRF.
13871474

13881475
For more info, look at the source code; each method is documented and details
13891476
about what it does and how to use it are provided. Make sure to also check the doc folder where

composer.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"name": "workivate/php-saml",
33
"description": "Workivate version of OneLogin PHP SAML Toolkit",
4+
"type": "library",
5+
"version": "4.1.0",
46
"license": "MIT",
57
"homepage": "https://developers.onelogin.com/saml/php",
68
"keywords": ["saml", "saml2", "onelogin"],
@@ -15,17 +17,23 @@
1517
"source": "https://github.com/workivate/php-saml/"
1618
},
1719
"require": {
18-
"php": ">=7.3",
20+
"php": ">=8.1",
1921
"robrichards/xmlseclibs": ">=3.1.1"
2022
},
2123
"require-dev": {
22-
"phpunit/phpunit": "^9.5.2",
24+
"phpunit/phpunit": "^9.5",
2325
"php-coveralls/php-coveralls": "^2.0",
26+
"sebastian/phpcpd": "^4.0 || ^5.0 || ^6.0 ",
27+
"phploc/phploc": "^4.0 || ^5.0 || ^6.0 || ^7.0",
2428
"pdepend/pdepend": "^2.8.0",
2529
"squizlabs/php_codesniffer": "^3.5.8",
26-
"vimeo/psalm": "^4.6"
30+
"phpstan/phpstan": "^1.3.0",
31+
"phpstan/phpstan-phpunit": "^1.0.0"
2732
},
2833
"config": {
34+
"platform": {
35+
"php": "8.1.0"
36+
},
2937
"optimize-autoloader": true,
3038
"sort-packages": true
3139
},

0 commit comments

Comments
 (0)