samlesa 3.4.2 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +260 -25
- package/build/src/binding-artifact.js +194 -285
- package/build/src/entity-idp.js +16 -1
- package/build/src/entity-sp.js +19 -17
- package/build/src/extractor.js +25 -5
- package/build/src/flow.js +1 -8
- package/build/src/schemaValidator.js +78 -63
- package/build/src/urn.js +109 -11
- package/build/src/utility.js +71 -0
- package/package.json +88 -75
- package/types/src/binding-artifact.d.ts +53 -25
- package/types/src/binding-artifact.d.ts.map +1 -1
- package/types/src/entity-idp.d.ts.map +1 -1
- package/types/src/entity-sp.d.ts +12 -14
- package/types/src/entity-sp.d.ts.map +1 -1
- package/types/src/extractor.d.ts +2 -1
- package/types/src/extractor.d.ts.map +1 -1
- package/types/src/flow.d.ts.map +1 -1
- package/types/src/schemaValidator.d.ts +18 -1
- package/types/src/schemaValidator.d.ts.map +1 -1
- package/types/src/urn.d.ts +61 -5
- package/types/src/urn.d.ts.map +1 -1
- package/types/src/utility.d.ts +17 -0
- package/types/src/utility.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -1,44 +1,279 @@
|
|
|
1
|
-
# samlify · [](https://app.circleci.com/pipelines/github/tngan/samlify) [](https://www.npmjs.com/package/samlify) [](https://www.npmjs.com/package/samlify) [](https://coveralls.io/github/tngan/samlify?branch=master)
|
|
2
|
+
|
|
3
|
+
> **High-level API for Single Sign On (SAML 2.0) based on samlify**
|
|
2
4
|
|
|
3
5
|
---
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
[English Version](#readmemd) | [中文版本](#readmecnm)
|
|
8
|
+
|
|
9
|
+
## 🔄 This Repository
|
|
10
|
+
|
|
11
|
+
This is an improved fork of [samlify](https://github.com/tngan/samlify) by [tngan](https://github.com/tngan).
|
|
6
12
|
|
|
7
13
|
### Key Improvements
|
|
8
14
|
|
|
9
|
-
- 📦 Converted from
|
|
10
|
-
- ✅ Replaced `@authenio/xml-encryption` with `xml-encryption
|
|
11
|
-
- ✅ Upgraded `@xmldom/xmldom` to the latest version
|
|
12
|
-
- 🛠️ Fixed encrypted assertion signature verification
|
|
13
|
-
- 📦 Added default `AttributeConsumingService` element generation for ServiceProvider
|
|
14
|
-
- 📦 Added partial Artifact binding support
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
- ✅ Tested against Burp SAML Raider (XSW and XXE attacks)
|
|
22
|
-
- ⚡ Migrated tests to Vitest
|
|
15
|
+
- 📦 **ESModule Support**: Converted from CommonJS to ESModule
|
|
16
|
+
- ✅ **Enhanced Encryption**: Replaced `@authenio/xml-encryption` with `xml-encryption`, added support for SHA-256/512 encryption key OAEP digest methods
|
|
17
|
+
- ✅ **Updated Dependencies**: Upgraded `@xmldom/xmldom` to the latest version
|
|
18
|
+
- 🛠️ **Fixed Encrypted Assertion**: Improved encrypted assertion signature verification with `EncryptedAssertion` field extraction
|
|
19
|
+
- 📦 **Default AttributeConsumingService**: Added default `AttributeConsumingService` element generation for ServiceProvider
|
|
20
|
+
- 📦 **Artifact Binding**: Added partial Artifact binding support
|
|
21
|
+
- 🔒 **Security Upgrades**: Default signature algorithm upgraded to SHA-256, default encryption to AES_256_GCM
|
|
22
|
+
- 🧪 **XML Validation**: Built-in XML XSD validator
|
|
23
|
+
- 🐛 **Bug Fixes**: Improved HTTP-Redirect binding handling without DEFLATE compression
|
|
24
|
+
- 🔓 **Auto Detection**: Automatic detection of encrypted assertions without explicit flags
|
|
25
|
+
- ✅ **Security Tested**: Tested against Burp SAML Raider (XSW and XXE attacks)
|
|
26
|
+
- ⚡ **Faster Testing**: Migrated tests to Vitest
|
|
23
27
|
|
|
24
28
|
---
|
|
25
29
|
|
|
26
|
-
##
|
|
30
|
+
## 📖 Documentation
|
|
31
|
+
|
|
32
|
+
Full documentation is available at [https://samlify.js.org](https://samlify.js.org).
|
|
27
33
|
|
|
28
|
-
|
|
34
|
+
### Quick Links
|
|
35
|
+
|
|
36
|
+
- [Getting Started](docs/guide.md)
|
|
37
|
+
- [Service Provider Configuration](docs/sp-configuration.md)
|
|
38
|
+
- [Identity Provider Configuration](docs/idp-configuration.md)
|
|
39
|
+
- [Supported Algorithms](#supported-algorithms)
|
|
40
|
+
- [Examples](docs/examples.md)
|
|
29
41
|
|
|
30
42
|
---
|
|
31
43
|
|
|
32
|
-
##
|
|
44
|
+
## 🚀 Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install samlesa
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 📦 Supported Algorithms
|
|
53
|
+
|
|
54
|
+
### Signature Algorithms
|
|
55
|
+
|
|
56
|
+
| Algorithm | URI | Security Level | Recommendation |
|
|
57
|
+
|-----------|-----|----------------|----------------|
|
|
58
|
+
| **RSA-SHA256** | `http://www.w3.org/2001/04/xmldsig-more#rsa-sha256` | ✅ High | ⭐ **Recommended** |
|
|
59
|
+
| RSA-SHA384 | `http://www.w3.org/2001/04/xmldsig-more#rsa-sha384` | ✅ High | ✅ Supported |
|
|
60
|
+
| RSA-SHA512 | `http://www.w3.org/2001/04/xmldsig-more#rsa-sha512` | ✅ High | ✅ Supported |
|
|
61
|
+
| RSA-PSS-SHA256 | `http://www.w3.org/2007/05/xmldsig-more#rsa-pss-sha256` | ✅✅ Very High | ✅ Supported |
|
|
62
|
+
| ECDSA-SHA256 | `http://www.w3.org/2007/05/xmldsig-more#ecdsa-sha256` | ✅ High | ✅ Supported |
|
|
63
|
+
| ECDSA-SHA384 | `http://www.w3.org/2007/05/xmldsig-more#ecdsa-sha384` | ✅ High | ✅ Supported |
|
|
64
|
+
| ECDSA-SHA512 | `http://www.w3.org/2007/05/xmldsig-more#ecdsa-sha512` | ✅ High | ✅ Supported |
|
|
65
|
+
| EdDSA-Ed25519 | `http://www.w3.org/2007/05/xmldsig-more#eddsa-ed25519` | ✅✅ Very High | ✅ Supported |
|
|
66
|
+
| EdDSA-Ed448 | `http://www.w3.org/2021/04/xmldsig-more#eddsa-ed448` | ✅✅ Very High | ✅ Supported |
|
|
67
|
+
| ~~RSA-SHA1~~ | `http://www.w3.org/2000/09/xmldsig#rsa-sha1` | ❌ Low | ⚠️ Deprecated |
|
|
68
|
+
|
|
69
|
+
### Encryption Algorithms (Data)
|
|
70
|
+
|
|
71
|
+
| Algorithm | URI | Mode | Recommendation |
|
|
72
|
+
|-----------|-----|------|----------------|
|
|
73
|
+
| **AES-256-GCM** | `http://www.w3.org/2009/xmlenc11#aes256-gcm` | GCM | ⭐ **Recommended** |
|
|
74
|
+
| AES-128-GCM | `http://www.w3.org/2009/xmlenc11#aes128-gcm` | GCM | ✅ Supported |
|
|
75
|
+
| AES-256-CBC | `http://www.w3.org/2001/04/xmlenc#aes256-cbc` | CBC | ✅ Supported |
|
|
76
|
+
| AES-128-CBC | `http://www.w3.org/2001/04/xmlenc#aes128-cbc` | CBC | ✅ Supported |
|
|
77
|
+
| AES-256-CTR | `http://www.w3.org/2009/xmlenc11#aes256-ctr` | CTR | ✅ Supported |
|
|
78
|
+
| ~~TripleDES~~ | `http://www.w3.org/2001/04/xmlenc#tripledes-cbc` | CBC | ⚠️ Legacy Only |
|
|
79
|
+
|
|
80
|
+
### Key Encryption Algorithms
|
|
81
|
+
|
|
82
|
+
| Algorithm | URI | Recommendation |
|
|
83
|
+
|-----------|-----|----------------|
|
|
84
|
+
| **RSA-OAEP-MGF1P** | `http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p` | ⭐ **Recommended** |
|
|
85
|
+
| RSA-OAEP | `http://www.w3.org/2009/xmlenc11#rsa-oaep` | ✅ Supported |
|
|
86
|
+
| AES-256-KW | `http://www.w3.org/2001/04/xmlenc#kw-aes256` | ✅ Supported |
|
|
87
|
+
| ~~RSA-1_5~~ | `http://www.w3.org/2001/04/xmlenc#rsa-1_5` | ⚠️ Deprecated |
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 🔧 Usage
|
|
92
|
+
|
|
93
|
+
### As a Service Provider (SP)
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { ServiceProvider, IdentityProvider } from 'samlesa';
|
|
97
|
+
|
|
98
|
+
// Initialize Service Provider
|
|
99
|
+
const sp = ServiceProvider({
|
|
100
|
+
metadata: readFileSync('./sp-metadata.xml'),
|
|
101
|
+
privateKey: readFileSync('./sp-key.pem'),
|
|
102
|
+
signingCert: readFileSync('./sp-cert.cer'),
|
|
103
|
+
isAssertionEncrypted: true,
|
|
104
|
+
wantAssertionsSigned: true,
|
|
105
|
+
wantMessageSigned: true,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Initialize Identity Provider
|
|
109
|
+
const idp = IdentityProvider({
|
|
110
|
+
metadata: readFileSync('./idp-metadata.xml'),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Create login request
|
|
114
|
+
const { context: samlRequest, entityEndpoint } = sp.createLoginRequest(idp, 'redirect');
|
|
115
|
+
|
|
116
|
+
// Parse login response
|
|
117
|
+
const { extract } = await sp.parseLoginResponse(idp, 'redirect', {
|
|
118
|
+
body: { SAMLResponse: responseFromIdp }
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
console.log('User:', extract.nameID);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### As an Identity Provider (IdP)
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
import { IdentityProvider, ServiceProvider } from 'samlesa';
|
|
128
|
+
|
|
129
|
+
// Initialize Identity Provider
|
|
130
|
+
const idp = IdentityProvider({
|
|
131
|
+
metadata: readFileSync('./idp-metadata.xml'),
|
|
132
|
+
privateKey: readFileSync('./idp-key.pem'),
|
|
133
|
+
signingCert: readFileSync('./idp-cert.cer'),
|
|
134
|
+
isAssertionEncrypted: true,
|
|
135
|
+
wantAuthnRequestsSigned: true,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Initialize Service Provider
|
|
139
|
+
const sp = ServiceProvider({
|
|
140
|
+
metadata: readFileSync('./sp-metadata.xml'),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Parse login request
|
|
144
|
+
const { extract } = await idp.parseLoginRequest(sp, 'redirect', {
|
|
145
|
+
query: { SAMLRequest: requestFromSp }
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Create login response
|
|
149
|
+
const { context: samlResponse } = await idp.createLoginResponse({
|
|
150
|
+
sp,
|
|
151
|
+
requestInfo: { extract },
|
|
152
|
+
binding: 'post',
|
|
153
|
+
user: { NameID: 'user@example.com' },
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Artifact Binding Support
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { ServiceProvider, IdentityProvider } from 'samlesa';
|
|
161
|
+
|
|
162
|
+
// Create SOAP login request (Artifact binding)
|
|
163
|
+
const soapRequest = await sp.createLoginSoapRequest(idp, 'artifact', {
|
|
164
|
+
inResponseTo: '_requestId',
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Parse Artifact Resolve request
|
|
168
|
+
const artifactResult = await sp.parseLoginRequestResolve(idp, soapXml);
|
|
33
169
|
|
|
34
|
-
|
|
170
|
+
// Resolve SAML Response by Artifact ID
|
|
171
|
+
const responseResult = await sp.parseLoginResponseResolve(idp, artifactId, request);
|
|
172
|
+
```
|
|
35
173
|
|
|
36
174
|
---
|
|
37
175
|
|
|
38
|
-
##
|
|
176
|
+
## 🔐 Security Features
|
|
39
177
|
|
|
40
|
-
|
|
178
|
+
- ✅ **XXE Protection**: Built-in XML External Entity attack prevention
|
|
179
|
+
- ✅ **XSW Protection**: Tested against XML Signature Wrapping attacks
|
|
180
|
+
- ✅ **Schema Validation**: XML Schema validation for all SAML messages
|
|
181
|
+
- ✅ **Signature Verification**: Comprehensive signature validation
|
|
182
|
+
- ✅ **Time Validation**: Configurable clock drift tolerance
|
|
183
|
+
- ✅ **Destination Validation**: Endpoint URL verification
|
|
184
|
+
- ✅ **Certificate Validation**: X.509 certificate validation
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## 📁 Project Structure
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
samlify/
|
|
192
|
+
├── src/ # Source code
|
|
193
|
+
│ ├── binding-artifact.ts # Artifact binding implementation
|
|
194
|
+
│ ├── binding-post.ts # POST binding implementation
|
|
195
|
+
│ ├── binding-redirect.ts # Redirect binding implementation
|
|
196
|
+
│ ├── entity-idp.ts # Identity Provider entity
|
|
197
|
+
│ ├── entity-sp.ts # Service Provider entity
|
|
198
|
+
│ ├── libsaml.ts # SAML utilities
|
|
199
|
+
│ └── schemaValidator.ts # XML Schema validation
|
|
200
|
+
├── test/ # Test files
|
|
201
|
+
│ ├── artifact.test.ts # Artifact binding tests
|
|
202
|
+
│ ├── flow.test.ts # Flow tests
|
|
203
|
+
│ └── key/ # Test certificates
|
|
204
|
+
├── docs/ # Documentation
|
|
205
|
+
└── scripts/ # Utility scripts
|
|
206
|
+
└── generate-certs.js # Certificate generation
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## 🧪 Testing
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
# Run all tests
|
|
215
|
+
npm test
|
|
216
|
+
|
|
217
|
+
# Run tests in watch mode
|
|
218
|
+
npm run test:watch
|
|
219
|
+
|
|
220
|
+
# Run with coverage
|
|
221
|
+
npm run test:coverage
|
|
222
|
+
|
|
223
|
+
# Run artifact binding tests only
|
|
224
|
+
npm run test:artifact
|
|
225
|
+
|
|
226
|
+
# Fast test run (parallel)
|
|
227
|
+
npm run test:fast
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## 🛠️ Development
|
|
41
233
|
|
|
42
234
|
```bash
|
|
43
|
-
|
|
44
|
-
|
|
235
|
+
# Install dependencies
|
|
236
|
+
npm install
|
|
237
|
+
|
|
238
|
+
# Build the project
|
|
239
|
+
npm run build
|
|
240
|
+
|
|
241
|
+
# Fast build (incremental)
|
|
242
|
+
npm run build:fast
|
|
243
|
+
|
|
244
|
+
# Generate test certificates (requires OpenSSL)
|
|
245
|
+
npm run generate-certs
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## 📝 License
|
|
251
|
+
|
|
252
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## 🤝 Contributing
|
|
257
|
+
|
|
258
|
+
Contributions are welcome! Please feel free to:
|
|
259
|
+
|
|
260
|
+
- Submit pull requests
|
|
261
|
+
- Report issues
|
|
262
|
+
- Provide integration examples with other frameworks
|
|
263
|
+
- Improve documentation
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## 📧 Support
|
|
268
|
+
|
|
269
|
+
- **Issues**: [GitHub Issues](https://github.com/Veclea/samlify/issues)
|
|
270
|
+
- **Documentation**: [https://samlify.js.org](https://samlify.js.org)
|
|
271
|
+
- **Email**: vemocle@gmail.com
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## 🔗 Related Links
|
|
276
|
+
|
|
277
|
+
- [Original samlify](https://github.com/tngan/samlify)
|
|
278
|
+
- [SAML 2.0 Specification](https://www.oasis-open.org/standards#samlv2.0)
|
|
279
|
+
- [SAML Raider (Security Testing)](https://github.com/SAMLRaider/SAMLRaider)
|