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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update parse url
  • Loading branch information
Veclea committed May 18, 2025
commit 1721859767fa1301afa2b6893dd1b4e592531185
122 changes: 98 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -5,51 +5,125 @@ Highly configurable Node.js SAML 2.0 library for Single Sign On

---

## 🔄 本仓库为 [samlify](https://github.com/tngan/samlify) 的改进分支

## 🔄 This repository is a fork of [samlify](https://github.com/tngan/samlify) with the following improvements:
## 🔄 本仓库为 [samlify](https://github.com/tngan/samlify) 的改进分支版本,原作者[tngan](https://github.com/tngan)

### 主要改进 / Key Improvements
- ✅ 将依赖包 `@authenio/xml-encryption` 替换为 `xml-encryption` 并升级版本,支持 SHA-256/512 加密和 OAEP 摘要方法
✅ Replaced `@authenio/xml-encryption` with `xml-encryption` (latest version adds SHA-256/512 and OAEP support)

- 🛠️ 修复加密断言逻辑,支持 `EncryptedAssertion` 字段提取
🛠️ Fixed encrypted assertion logic to handle `EncryptedAssertion` field
- 📦 将 CJS模块打包转为 ESModule

- 📦 默认配置增加 `AttributeConsumingService` 和属性声明生成
📦 Added `AttributeConsumingService` to default elements and attribute value generation
- ✅ 将依赖包 `@authenio/xml-encryption` 替换为 `xml-encryption` 并升级版本对 sha256/512 加密密钥 OAEP 摘要方法的支持

- 🗑️ 移除自定义函数模板,通过 `AttributeStatement` 配置多值属性
🗑️ Removed custom templates, added multi-value attribute support via `AttributeStatement`
- 🛠️ 修复加密断言验证签名函数 verifySignature 提取`Assertion` 字段的错误,增加对加密断言 `EncryptedAssertion` 字段提取逻辑

- 🔒 签名算法升级为 SHA-256+,默认加密算法 AES_256_GCM
🔒 Upgraded signature algorithm to SHA-256+, default encryption to AES_256_GCM
- 📦 ServiceProvider实例化函数 attributeConsumingService字段参函数, 生成默认的 `AttributeConsumingService` 元素和属性值

- 📦 将 CJS 模块打包转为 ESModule
📦 Migrated from CJS to ESModule packaging
- 🗑️ 移除作为Idp使用 IdentityProvider 函数自定义函数模板loginResponseTemplate字段的支持,并改进了自定义函数替换。
改进createLoginResponse函数签名改为对象的传参方式

- ⚙️ 将 `createLoginResponse` 改为对象传参,新增 `AttributeStatement` 参数
⚙️ Refactored `createLoginResponse` to use object parameters with `AttributeStatement`
- 🔒 默认签名算法升级为 SHA-256,Idp默认加密算法为 AES_256_GCM

- ⬆️ 升级依赖版本,移除 `node-rsa`/`node-forge`,改用原生 `crypto` 模块
⬆️ Upgraded dependencies, replaced `node-rsa`/`node-forge` with native `crypto`
- ⬆️ 升级所有能够升级的依赖版本,移除 `node-rsa`/`node-forge` 模块儿,改用原生nodejs `crypto` 模块实现。

- 🌐 将 `url` 库替换为 `URL` 原生 API
🌐 Replaced `url` library with native `URL` API
- 🌐 将 `url` 库替换为 `URL` 原生 API
- 改进了如果响应为的绑定`urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect`,某些情况下未能DEFLATE压缩导致不能提取xml的异常情况的处理
- 现在如果遇到加密响应无需显示传递 `isAssertionEncrypted` 字段,也无需传递 `MessageSignatureOrder`
字段。因为我认为是否加密应该是可以自动判断的,MessageSignatureOrder我修改了判断逻辑并在Keycloak 验证可以通过。使用前你应该自行验证这其中的风险
- 默认 elementsOrder 增加了 AttributeConsumingService 适配
- 我已经使用 Burp SAML Raider测试了 八种XSW都能良好的应对,以及XXE。你应该自行验证

---

## 欢迎 PR / Welcome PRs

欢迎贡献代码或提供与其他框架集成的用例
Welcome contributions or integration examples with frameworks

---

## 安装 / Installation
宁应该在使用的前提下首先设置验证其
```js
import * as samlify from 'samlify';
import * as validator from '@authenio/samlify-xsd-schema-validator';

import * as validator from '@authenio/samlify-xsd-schema-validator';
import * as Saml from "samlesa";
import {Extractor,} from "samlesa";
import validator from '@authenio/samlify-node-xmllint'
// 设置模式验证器 / Set schema validator
samlify.setSchemaValidator(validator);
Saml.setSchemaValidator(validator);


```

## 生成密钥

我们使用 openssl 生成密钥和证书用于测试。私钥可以使用密码保护,这是可选的。以下是生成私钥和自签名证书的命令。

> openssl genrsa -passout pass:foobar -out encryptKey.pem 4096
> openssl req -new -x509 -key encryptKey.pem -out encryptionCert.cer -days 3650

## 当您作为IDP的伪代码使用示例

```js
/** 本代码正对不同的绑定做出的方式伪代码*/
if (request.method === 'GET') {
data = request.query
bind = 'redirect'
infoQuery.query = request.query
let compressedResult = validateAndInflateSamlResponse(data.SAMLResponse)
console.log(compressedResult);
console.log("压缩结果---------------------")
infoQuery.octetString = buildOctetStringFromQuery(request.query)
dataResult = Extractor.extract(compressedResult.xml, loginResponseFields);
}
if (request.method === 'POST') {
data = request.body
bind = 'post'
infoQuery.body = request.body
dataResult = Extractor.extract(Base64.decode(decodeURIComponent(data.SAMLResponse)), loginResponseFields)
}
/** 宁应该自行实施根据响应提取出来的Issur去数据库查找元数据*/
// 1. 提取SAML发行者信息
if (!dataResult.issuer) {
return reply.view('errorHtml.html', {
errorMessage: `无效的发行者`, errorCode: StatusCode?.Responder, requestId: ""
})
}

let result = await samlCollection.findOne({issuer:dataResult.issuer});
const idp = new Saml.IdentityProvider({
metadata: result.metadata,
});

/** 检查断言*/
let extract = null
/** 先看数据库有没有*/
let bindType = 'post' //redirect post ......您应该自定判断
let parseResult = await sp.parseLoginResponse(idp, bindType, infoQuery)

/**如果解析成功 你应该去验证元素结果中的 attribute 和 Audience issur是否是你期待的 inResponseTo检查 是否有必须的属性没有 都需要您进行严密的的考察 */

if(upaboveFieldCheckAllSuccess){
return repla.view('success.ejs',{...your template data})
}
/*success.ejs template example */
/**/
<!-- 隐藏的 SAML 表单 -->
/*
<form id="saml-form" method="post" action="<%= entityEndpoint %>" style="display: none;">
<input type="hidden" name="<%= type %>" value="<%= context %>" />
<input type="hidden" name="RelayState" value="<%= relayState %>" />
</form>

<script>
// 延迟 1.5 秒提交以展示加载效果

document.getElementById('saml-form').submit();

// 兼容性处理:若 5 秒后仍未跳转显示提示
setTimeout(() => {
document.querySelector('.loading-subtext').textContent =
'跳转时间较长,请检查网络或联系系统管理员';
}, 1500);
</script>*/

```