Skip to content

I've made some changes for better parsing and validation #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 143 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
1891991
update some error
Veclea May 12, 2025
afcc5bb
update some error
Veclea May 12, 2025
8c4fc6a
some change
Veclea May 13, 2025
4441ddc
change es module
Veclea May 13, 2025
a3410ac
change es module
Veclea May 13, 2025
371d298
change es module
Veclea May 13, 2025
f5e3ab9
change es module
Veclea May 13, 2025
ecf6cf5
Merge remote-tracking branch 'origin/master'
Veclea May 13, 2025
9b90a05
change es module
Veclea May 13, 2025
c7c592f
update some error
Veclea May 13, 2025
7924224
remove node-forge
Veclea May 13, 2025
ac8e524
remove node-forge
Veclea May 13, 2025
3f98c94
remove node-forge
Veclea May 13, 2025
559ce44
add nodejs crypto verify
Veclea May 13, 2025
411ef84
add nodejs crypto verify
Veclea May 13, 2025
b15afe6
add nodejs crypto verify
Veclea May 13, 2025
6f3842b
add nodejs crypto verify
Veclea May 14, 2025
aee9e40
add nodejs crypto verify
Veclea May 14, 2025
27ca541
add nodejs crypto verify
Veclea May 14, 2025
c8255d2
add nodejs crypto verifyn
Veclea May 14, 2025
550d4dc
update NameId
Veclea May 14, 2025
a205b69
update NameId
Veclea May 14, 2025
3eb6ae8
update NameId
Veclea May 14, 2025
8800e5d
update NameId
Veclea May 14, 2025
93204fa
update NameId
Veclea May 14, 2025
9a839ce
update NameId
Veclea May 14, 2025
f261466
CHANGE TO getReferences
Veclea May 15, 2025
1fc53da
CHANGE TO getReferences
Veclea May 15, 2025
249e3f4
update Attribute
Veclea May 15, 2025
879b95d
update Attribute
Veclea May 15, 2025
aa59883
update Attribute
Veclea May 15, 2025
4cb3ebb
update Attribute
Veclea May 15, 2025
d9cc4e6
update Attribute
Veclea May 15, 2025
80cbedc
update Attribute
Veclea May 15, 2025
3110dcb
update Attribute
Veclea May 15, 2025
ea5f448
update NameId
Veclea May 15, 2025
e85e306
update NameId
Veclea May 15, 2025
2760e94
update NameId
Veclea May 15, 2025
7263172
update NameId
Veclea May 16, 2025
8c02de3
update cjs to esm
Veclea May 16, 2025
ac15e6b
update cjs to esm
Veclea May 16, 2025
1e22c99
update reademe
Veclea May 16, 2025
e34681a
update reademe
Veclea May 16, 2025
f83282d
update reademe
Veclea May 16, 2025
0307b1b
update reademe
Veclea May 16, 2025
27d7480
update reademe
Veclea May 16, 2025
941212f
update reademe
Veclea May 16, 2025
55ede4f
update reademe
Veclea May 16, 2025
037ed4c
update reademe
Veclea May 16, 2025
16fda14
update artifactResolutionService
Veclea May 16, 2025
63414b6
update artifactResolutionService
Veclea May 16, 2025
fdab694
update artifactResolutionService
Veclea May 16, 2025
1fe4d58
update artifbind
Veclea May 16, 2025
6e8e2f7
update parse
Veclea May 17, 2025
e76197d
update parse
Veclea May 17, 2025
10009c9
update parse
Veclea May 17, 2025
f6e1768
update parse url
Veclea May 18, 2025
a217c87
update parse url
Veclea May 18, 2025
1721859
update parse url
Veclea May 18, 2025
f2bccd8
update parse url
Veclea May 18, 2025
1f448e2
update default validate
Veclea May 19, 2025
8f64ddf
update default validate
Veclea May 19, 2025
907677c
update default validate
Veclea May 19, 2025
9f4acba
update default validate
Veclea May 19, 2025
e8feae7
update default validate
Veclea May 19, 2025
5bfdab9
update default validate
Veclea May 19, 2025
e48b4bb
update default validate
Veclea May 30, 2025
799c9d2
update default validate
Veclea May 30, 2025
e14a212
update default validate
Veclea May 30, 2025
0050ffb
update parse url
Veclea May 31, 2025
4180bb8
update some version
Veclea Jun 30, 2025
e763eea
update parse url
Veclea Jul 2, 2025
d001ed9
update some version
Veclea Jul 3, 2025
bd2e757
update some version
Veclea Jul 3, 2025
fe512ef
update some version
Veclea Jul 4, 2025
723f575
init ArtAct工件
Veclea Jul 4, 2025
fda1a41
init ArtAct工件
Veclea Jul 4, 2025
714797b
init ArtAct工件
Veclea Jul 4, 2025
f43d5e6
init ArtAct工件
Veclea Jul 4, 2025
b08b017
init ArtAct工件
Veclea Jul 4, 2025
6bdd320
init ArtAct工件
Veclea Jul 4, 2025
b32f76c
init ArtAct工件
Veclea Jul 4, 2025
5191aba
init ArtAct工件
Veclea Jul 4, 2025
c0b517d
init ArtAct工件
Veclea Jul 4, 2025
af1bd84
init ArtAct工件
Veclea Jul 4, 2025
40c1fe9
init ArtAct工件
Veclea Jul 4, 2025
08e2281
update artifact post support
Veclea Jul 4, 2025
6e25d04
update artifact post support
Veclea Jul 5, 2025
5f0ff12
update artifact post support
Veclea Jul 5, 2025
67b58c9
update artifact post support
Veclea Jul 5, 2025
54489f6
update schema
Veclea Jul 5, 2025
3f2671d
update schema
Veclea Jul 5, 2025
dae0feb
update schema
Veclea Jul 5, 2025
cd3b7a8
update schema
Veclea Jul 5, 2025
03060ed
update schema
Veclea Jul 6, 2025
0d5c854
update schema
Veclea Jul 6, 2025
9304010
update schema
Veclea Jul 6, 2025
e739f10
update schema
Veclea Jul 6, 2025
2c551f6
update schema
Veclea Jul 6, 2025
d7dae0e
init ArtAct工件
Veclea Jul 7, 2025
34e801d
init ArtAct工件
Veclea Jul 7, 2025
6696980
init ArtAct工件
Veclea Jul 7, 2025
255e72f
change ava test to vitest test
Veclea Jul 7, 2025
f0368c2
change ava test to vitest test
Veclea Jul 7, 2025
f86ae46
change ava test to vitest test
Veclea Jul 7, 2025
1f55412
change ava test to vitest test
Veclea Jul 7, 2025
7315c94
change ava test to vitest test
Veclea Jul 7, 2025
2a36afe
change ava test to vitest test
Veclea Jul 7, 2025
b1050cd
change ava test to vitest test
Veclea Jul 7, 2025
1db5876
change ava test to vitest test
Veclea Jul 7, 2025
96ef8ef
update vitest
Veclea Jul 7, 2025
3607d66
update vitest
Veclea Jul 7, 2025
3ad939b
update vitest
Veclea Jul 7, 2025
0e96703
update vitest
Veclea Jul 7, 2025
02e79a3
change ava test to vitest test
Veclea Jul 8, 2025
fd2a157
change ava test to vitest test
Veclea Jul 8, 2025
9afc585
change ava test to vitest test
Veclea Jul 8, 2025
f5b4c1c
change ava test to vitest test
Veclea Jul 8, 2025
cbf55a0
change ava test to vitest test
Veclea Jul 8, 2025
b719aed
change ava test to vitest test
Veclea Jul 8, 2025
b167ec1
change ava test to vitest test
Veclea Jul 8, 2025
9c30abf
change ava test to vitest test
Veclea Jul 8, 2025
f63f957
pass most test
Veclea Jul 8, 2025
96bb3b9
pass all vitest test
Veclea Jul 8, 2025
798d0c6
pass all vitest test
Veclea Jul 8, 2025
ac82a09
pass all vitest test
Veclea Jul 8, 2025
7c2cddf
pass all vitest test
Veclea Jul 8, 2025
cec580d
change ava test to vitest test
Veclea Jul 10, 2025
82af4b0
change ava test to vitest test
Veclea Jul 10, 2025
95eafb8
change ava test to vitest test
Veclea Jul 10, 2025
8e08cbe
pass all vitest test
Veclea Jul 10, 2025
fef7bd7
change ava test to vitest test
Veclea Jul 11, 2025
341764d
pass all vitest test
Veclea Jul 15, 2025
b5a46b3
change ava test to vitest test
Veclea Jul 15, 2025
4334872
change ava test to vitest test
Veclea Jul 15, 2025
9027b88
update validate artifact response
Veclea Jul 16, 2025
1d97eae
update validate artifact response
Veclea Jul 16, 2025
3286346
update validate artifact response
Veclea Jul 16, 2025
b582040
update validate artifact response
Veclea Jul 16, 2025
92b15d3
update validate artifact response
Veclea Jul 16, 2025
0f1ec0a
update validate artifact response
Veclea Jul 17, 2025
f03562e
update validate artifact response
Veclea Jul 17, 2025
9f0b1a6
update validate artifact response
Veclea Aug 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "NodeNext"
}
}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ logs
pids
*.pid
*.seed

types
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

Expand All @@ -33,4 +33,4 @@ types/

*.tgz

package-lock.json
package-lock.json
3 changes: 3 additions & 0 deletions @types/xml-encryption.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ declare module "xml-encryption" {
encryptionAlgorithm: string;
keyEncryptionAlgorithm: string;
input_encoding?: string;
keyEncryptionDigest?: string,
warnInsecureAlgorithm?: boolean,
disallowEncryptionWithInsecureAlgorithm?: boolean,
}
export interface DecryptOptions {
key: string | Buffer;
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)

Copyright (c) 2023 veclea
Copyright (c) 2016-present Tony Ngan

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
99 changes: 34 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,44 @@
# samlify ·

[![Build Status](https://img.shields.io/circleci/build/github/tngan/samlify?style=for-the-badge&logo=circleci)](https://app.circleci.com/pipelines/github/tngan/samlify)
[![npm version](https://img.shields.io/npm/v/samlify.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/samlify)
[![NPM](https://img.shields.io/npm/dm/samlify.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/samlify)
[![Coverage Status](https://img.shields.io/coveralls/tngan/samlify/master.svg?style=for-the-badge&logo=coveralls)](https://coveralls.io/github/tngan/samlify?branch=master)

Highly configuarable Node.js SAML 2.0 library for Single Sign On
# samlify · [![构建状态](https://img.shields.io/circleci/build/github/tngan/samlify?style=for-the-badge&logo=circleci)](https://app.circleci.com/pipelines/github/tngan/samlify) [![npm 版本](https://img.shields.io/npm/v/samlify.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/samlify) [![下载量](https://img.shields.io/npm/dm/samlify.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/samlify) [![覆盖率](https://img.shields.io/coveralls/tngan/samlify/master.svg?style=for-the-badge&logo=coveralls)](https://coveralls.io/github/tngan/samlify?branch=master)

---
[English Version](#README.md) | [中文版本](#readmeCN.md)
## 🔄 This repository is an improved fork of [samlify](https://github.com/tngan/samlify) by [tngan](https://github.com/tngan)

### Key Improvements

- 📦 Converted from CJS to ESModule
- ✅ Replaced `@authenio/xml-encryption` with `xml-encryption` and added support for sha256/512 encryption key OAEP digest methods
- ✅ Upgraded `@xmldom/xmldom` to the latest version
- 🛠️ Fixed encrypted assertion signature verification by adding `EncryptedAssertion` field extraction logic
- 📦 Added default `AttributeConsumingService` element generation for ServiceProvider
- 📦 Added partial Artifact binding support
- 🗑️ Removed custom template support for IdentityProvider and improved parameter passing
- 🔒 Upgraded default signature algorithm to SHA-256 and default encryption to AES_256_GCM
- 🧪 Added built-in XML XSD validator
- 🐛 Improved handling of HTTP-Redirect binding without DEFLATE compression
- 🔓 Automatic detection of encrypted assertions without explicit flags
- 📝 Added AttributeConsumingService to default elementsOrder
- ✅ Tested against Burp SAML Raider (XSW and XXE attacks)
- ⚡ Migrated tests to Vitest

---

## Welcome PRs

Welcome all PRs for maintaining this project, or provide a link to the repositories especially for use cases alongside with different frameworks.

### Installation

Multiple schema validators are currently supported by our system, with couple validator modules available and the option to create custom ones. It is essential to utilize the setSchemaValidator function at the outset to avoid errors.

```js
import * as samlify from 'samlify';
import * as validator from '@authenio/samlify-xsd-schema-validator';
// import * as validator from '@authenio/samlify-validate-with-xmllint';
// import * as validator from '@authenio/samlify-node-xmllint';

samlify.setSchemaValidator(validator);
```

Now you can create your own schema validator and even suppress it but you have to take the risk for accepting malicious response.

```typescript
samlify.setSchemaValidator({
validate: (response: string) => {
/* implment your own or always returns a resolved promise to skip */
return Promise.resolve('skipped');
}
});
```

For those using Windows, `windows-build-tools` should be installed globally before installing samlify if you are using `libxml` validator.

```console
yarn global add windows-build-tools
```

### Development

This project is now developed using TypeScript, also support Yarn which is a new package manager.

```console
yarn global add typescript
yarn
```

### Get Started

```javascript
const saml = require('samlify');
```

See full documentation [here](https://samlify.js.org/)

### Example
Contributions are welcome! Please feel free to submit pull requests or provide integration examples with other frameworks.

[react-samlify](https://github.com/passify/react-samlify) SP example powered by React, TypeScript and Webpack
---

### Talks
## How to use?

[An introduction to Single Sign On](http://www.slideshare.net/TonyNgan/an-introduction-of-single-sign-on)
Refer to the `type/flows.test.ts` test cases and the original documentation at [https://samlify.js.org](https://samlify.js.org). Note that some parameters have been changed in this fork.

### License
---

[MIT](LICENSE)
## Generating Keys

### Copyright
Use OpenSSL to generate keys and certificates for testing. Private keys can be password-protected (optional). Here are the commands:

Copyright (C) 2016-present Tony Ngan, released under the MIT License.
```bash
openssl genrsa -passout pass:foobar -out encryptKey.pem 4096
openssl req -new -x509 -key encryptKey.pem -out encryptionCert.cer -days 3650
48 changes: 48 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@echo off
set PROJECT=samlify

if "%1" == "install" goto install
if "%1" == "clean" goto clean
if "%1" == "rebuild" goto rebuild
if "%1" == "pretest" goto pretest
if "%1" == "doc" goto doc
if "%1" == "install_jdk" goto install_jdk

echo Usage: build.bat [install^|clean^|rebuild^|pretest^|doc^|install_jdk]
goto end

:install
echo Installing %PROJECT%
npm install
goto end

:clean
echo Cleaning node_modules
rmdir /s /q node_modules
goto end

:rebuild
call :clean
echo Rebuilding...
mkdir build
tsc
goto end

:pretest
echo Preparing tests...
mkdir build\test 2>nul
xcopy test\key build\test\key /E /I /Y
xcopy test\misc build\test\misc /E /I /Y
goto end

:doc
echo Serving docs with docsify...
docsify serve ./docs
goto end

:install_jdk
echo JDK installation is not applicable on Windows via this script.
echo Please manually install OpenJDK from https://adoptium.net/
goto end

:end
18 changes: 18 additions & 0 deletions buils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { build } from 'esbuild'
import { dirname } from 'path'
import { fileURLToPath } from 'url'

// 获取当前目录的 ESM 兼容方式
const __dirname = dirname(fileURLToPath(import.meta.url))

// 使用 esbuild 进行高级构建
await build({
entryPoints: ['src/index.ts'], // 入口文件
bundle: true, // 打包所有依赖
minify: true, // 压缩代码
outfile: 'dist/index.min.js', // 输出文件路径
platform: 'node', // 目标平台
target: 'node20', // Node.js 20+ 环境
format: 'esm', // 输出格式为 ESM
sourcesContent: false // 不包含源码内容
})
10 changes: 10 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import IdentityProvider, { IdentityProvider as IdentityProviderInstance } from './src/entity-idp';
import ServiceProvider, { ServiceProvider as ServiceProviderInstance } from './src/entity-sp';
export { default as IdPMetadata } from './src/metadata-idp';
export { default as SPMetadata } from './src/metadata-sp';
export { default as Utility } from './src/utility';
export { default as SamlLib } from './src/libsaml';
import * as Constants from './src/urn';
import * as Extractor from './src/extractor';
import { setSchemaValidator, setDOMParserOptions } from './src/api';
export { Constants, Extractor, IdentityProvider, IdentityProviderInstance, ServiceProvider, ServiceProviderInstance, setSchemaValidator, setDOMParserOptions };
19 changes: 19 additions & 0 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 17 additions & 12 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// version <= 1.25
import IdentityProvider, { IdentityProvider as IdentityProviderInstance } from './src/entity-idp';
import ServiceProvider, { ServiceProvider as ServiceProviderInstance } from './src/entity-sp';
import IdentityProvider, { IdentityProvider as IdentityProviderInstance } from './src/entity-idp.js';
import ServiceProvider, { ServiceProvider as ServiceProviderInstance } from './src/entity-sp.js';

export { default as IdPMetadata } from './src/metadata-idp';
export { default as SPMetadata } from './src/metadata-sp';
export { default as Utility } from './src/utility';
export { default as SamlLib } from './src/libsaml';
export { default as IdPMetadata } from './src/metadata-idp.js';
export { default as SPMetadata } from './src/metadata-sp.js';
export { default as Utility } from './src/utility.js';
export { default as SamlLib } from './src/libsaml.js';
// roadmap
// new name convention in version >= 3.0
import * as Constants from './src/urn';
import * as Extractor from './src/extractor';

import * as Constants from './src/urn.js';
import * as Extractor from './src/extractor.js';
import * as Soap from './src/soap.js';
import {validate,validateMetadata} from './src/schemaValidator.js'
// exposed methods for customizing samlify
import { setSchemaValidator, setDOMParserOptions } from './src/api';
import { setSchemaValidator, setDOMParserOptions } from './src/api.js';

export {
Constants,
Expand All @@ -24,5 +25,9 @@ export {
ServiceProviderInstance,
// set context
setSchemaValidator,
setDOMParserOptions
};
setDOMParserOptions,
validate,
validateMetadata,
Soap

};
Loading