cloudcms-server 3.3.1-beta.9 → 4.0.0-beta.2

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.
Files changed (108) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/broadcast/broadcast.js +6 -3
  4. package/broadcast/providers/redis.js +24 -49
  5. package/clients/nrp.js +117 -0
  6. package/clients/redis.js +64 -0
  7. package/d1/index.js +629 -0
  8. package/d1/index.js.works +203 -0
  9. package/d1/package.json +86 -0
  10. package/d1/package.json.works +14 -0
  11. package/duster/helpers/sample/nyt.js +2 -1
  12. package/framework/controllers.js +4 -4
  13. package/index.js +21 -14
  14. package/insight/insight.js +1 -1
  15. package/launchpad/index.js +203 -11
  16. package/launchpad/launchers/cluster.js +103 -110
  17. package/launchpad/launchers/redis.js +70 -0
  18. package/launchpad/launchers/single.js +36 -22
  19. package/locks/locks.js +63 -9
  20. package/locks/providers/cluster.js +3 -1
  21. package/locks/providers/memory.js +10 -7
  22. package/locks/providers/redis.js +62 -82
  23. package/middleware/admin/admin.js +3 -3
  24. package/middleware/authentication/adapters/session.js +11 -8
  25. package/middleware/authentication/authentication.js +28 -16
  26. package/middleware/authentication/authenticators/default.js +5 -2
  27. package/middleware/authentication/authenticators/session.js +5 -2
  28. package/middleware/authentication/providers/saml.js +1 -1
  29. package/middleware/authorization/authorization.js +11 -8
  30. package/middleware/awareness/awareness.js +55 -31
  31. package/middleware/awareness/plugins/editorial.js +4 -4
  32. package/middleware/awareness/providers/abstract-async.js +107 -84
  33. package/middleware/awareness/providers/abstract.js +1 -1
  34. package/middleware/awareness/providers/memory.js +0 -14
  35. package/middleware/awareness/providers/redis.js +186 -279
  36. package/middleware/cache/cache.js +4 -2
  37. package/middleware/cache/providers/redis.js +127 -89
  38. package/middleware/cache/providers/shared-memory.js +3 -3
  39. package/middleware/cloudcms/cloudcms.js +22 -16
  40. package/middleware/form/form.js +3 -3
  41. package/middleware/modules/modules.js +6 -3
  42. package/middleware/proxy/proxy.js +8 -21
  43. package/middleware/stores/stores.js +2 -2
  44. package/middleware/virtual-config/virtual-config.js +11 -8
  45. package/middleware/wcm/wcm.js +4 -4
  46. package/notifications/notifications.js +2 -2
  47. package/package.json +29 -25
  48. package/server/index.js +504 -415
  49. package/server/standalone.js +9 -0
  50. package/temp/clusterlock/index.js +3 -3
  51. package/temp/clusterlock/package.json +1 -1
  52. package/temp/passport-saml/LICENSE +23 -0
  53. package/temp/passport-saml/README.md +406 -0
  54. package/temp/passport-saml/lib/node-saml/algorithms.d.ts +5 -0
  55. package/temp/passport-saml/lib/node-saml/algorithms.js +41 -0
  56. package/temp/passport-saml/lib/node-saml/algorithms.js.map +1 -0
  57. package/temp/passport-saml/lib/node-saml/index.d.ts +3 -0
  58. package/temp/passport-saml/lib/node-saml/index.js +6 -0
  59. package/temp/passport-saml/lib/node-saml/index.js.map +1 -0
  60. package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.d.ts +45 -0
  61. package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.js +86 -0
  62. package/temp/passport-saml/lib/node-saml/inmemory-cache-provider.js.map +1 -0
  63. package/temp/passport-saml/lib/node-saml/saml-post-signing.d.ts +3 -0
  64. package/temp/passport-saml/lib/node-saml/saml-post-signing.js +15 -0
  65. package/temp/passport-saml/lib/node-saml/saml-post-signing.js.map +1 -0
  66. package/temp/passport-saml/lib/node-saml/saml.d.ts +77 -0
  67. package/temp/passport-saml/lib/node-saml/saml.js +1170 -0
  68. package/temp/passport-saml/lib/node-saml/saml.js.map +1 -0
  69. package/temp/passport-saml/lib/node-saml/types.d.ts +95 -0
  70. package/temp/passport-saml/lib/node-saml/types.js +8 -0
  71. package/temp/passport-saml/lib/node-saml/types.js.map +1 -0
  72. package/temp/passport-saml/lib/node-saml/utility.d.ts +3 -0
  73. package/temp/passport-saml/lib/node-saml/utility.js +19 -0
  74. package/temp/passport-saml/lib/node-saml/utility.js.map +1 -0
  75. package/temp/passport-saml/lib/node-saml/xml.d.ts +21 -0
  76. package/temp/passport-saml/lib/node-saml/xml.js +140 -0
  77. package/temp/passport-saml/lib/node-saml/xml.js.map +1 -0
  78. package/temp/passport-saml/lib/passport-saml/index.d.ts +6 -0
  79. package/temp/passport-saml/lib/passport-saml/index.js +11 -0
  80. package/temp/passport-saml/lib/passport-saml/index.js.map +1 -0
  81. package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.d.ts +13 -0
  82. package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.js +63 -0
  83. package/temp/passport-saml/lib/passport-saml/multiSamlStrategy.js.map +1 -0
  84. package/temp/passport-saml/lib/passport-saml/strategy.d.ts +20 -0
  85. package/temp/passport-saml/lib/passport-saml/strategy.js +167 -0
  86. package/temp/passport-saml/lib/passport-saml/strategy.js.map +1 -0
  87. package/temp/passport-saml/lib/passport-saml/types.d.ts +51 -0
  88. package/temp/passport-saml/lib/passport-saml/types.js +11 -0
  89. package/temp/passport-saml/lib/passport-saml/types.js.map +1 -0
  90. package/temp/passport-saml/package.json +96 -0
  91. package/util/auth.js +6 -6
  92. package/util/cloudcms.js +106 -118
  93. package/util/proxy-factory.js +159 -268
  94. package/util/redis.js +113 -0
  95. package/util/renditions.js +12 -6
  96. package/util/request.js +12 -6
  97. package/util/util.js +16 -2
  98. package/launchpad/launchers/sticky-cluster.js +0 -43
  99. package/temp/memored/.jshintrc +0 -4
  100. package/temp/memored/README.md +0 -240
  101. package/temp/memored/demo/demo1.js +0 -37
  102. package/temp/memored/demo/demo2.js +0 -32
  103. package/temp/memored/gulpfile.js +0 -8
  104. package/temp/memored/index.js +0 -343
  105. package/temp/memored/package.json +0 -54
  106. package/temp/memored/spec/memored.spec.js +0 -265
  107. package/web/cms/ice.js +0 -109
  108. package/web/cms/preview.js +0 -106
@@ -36,6 +36,9 @@ server.after(function(app, callback) {
36
36
  server.report(function(callback) {
37
37
 
38
38
  var cpuCount = require('os').cpus().length;
39
+ if (process.env.FORCE_SINGLE_CPU) {
40
+ cpuCount = 1;
41
+ }
39
42
 
40
43
  var port = process.env.PORT;
41
44
 
@@ -46,6 +49,7 @@ server.report(function(callback) {
46
49
  console.log("Gitana Scheme: " + process.env.GITANA_PROXY_SCHEME);
47
50
  console.log("Gitana Host: " + process.env.GITANA_PROXY_HOST);
48
51
  console.log("Gitana Port: " + process.env.GITANA_PROXY_PORT);
52
+ console.log("Gitana Path: " + process.env.GITANA_PROXY_PATH);
49
53
  console.log("CPU Count: " + cpuCount);
50
54
 
51
55
  var virtualHost = null;
@@ -68,6 +72,11 @@ server.report(function(callback) {
68
72
  console.log("Hosts Directory: " + process.env.CLOUDCMS_HOSTS_PATH);
69
73
  console.log("LaunchPad Mode: " + process.env.CLOUDCMS_LAUNCHPAD_SETUP);
70
74
  console.log("Max Files Detected: " + process.env.CLOUDCMS_MAX_FILES);
75
+ console.log("Session Type: " + process.configuration.session.type);
76
+
77
+ if (process.configuration.https) {
78
+ console.log("Server is configured to use HTTPS");
79
+ }
71
80
 
72
81
  console.log("");
73
82
 
@@ -5,7 +5,7 @@
5
5
  var path = require("path");
6
6
  var cluster = require("cluster");
7
7
 
8
- var ReadWriteLock = require("rwlock");
8
+ var AsyncLock = require('async-lock');
9
9
 
10
10
  var releaseFunctions = {};
11
11
 
@@ -18,7 +18,7 @@ var _setup = function() {
18
18
 
19
19
  if (cluster.isMaster)
20
20
  {
21
- var lock = new ReadWriteLock();
21
+ var lock = new AsyncLock();
22
22
 
23
23
  var _claim = function(message)
24
24
  {
@@ -26,7 +26,7 @@ var _setup = function() {
26
26
 
27
27
  var ticket = "ticket-" + message.id;
28
28
 
29
- lock.writeLock(key, function(releaseFn) {
29
+ lock.acquire(key, function(releaseFn) {
30
30
 
31
31
  releaseFunctions[ticket] = releaseFn;
32
32
 
@@ -13,7 +13,7 @@
13
13
  "shared"
14
14
  ],
15
15
  "devDependencies": {
16
- "rwlock": "^5.0.0"
16
+ "async-lock": "^1.3.2"
17
17
  },
18
18
  "maintainers": [
19
19
  {
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2012 Henri Bergius
2
+ Copyright (c) 2011 Michael Bosworth
3
+
4
+ Permission is hereby granted, free of charge, to any person
5
+ obtaining a copy of this software and associated documentation
6
+ files (the "Software"), to deal in the Software without
7
+ restriction, including without limitation the rights to use,
8
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following
11
+ conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,406 @@
1
+ # Passport-SAML
2
+
3
+ [![Build Status](https://github.com/node-saml/passport-saml/workflows/Build%20Status/badge.svg)](https://github.com/node-saml/passport-saml/actions?query=workflow%3ABuild%Status) [![GitHub version](https://badge.fury.io/gh/node-saml%2Fpassport-saml.svg)](https://badge.fury.io/gh/node-saml%2Fpassport-saml) [![npm version](https://badge.fury.io/js/passport-saml.svg)](http://badge.fury.io/js/passport-saml) [![NPM](https://nodei.co/npm/passport-saml.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/passport-saml/) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
4
+
5
+ This is a [SAML 2.0](http://en.wikipedia.org/wiki/SAML_2.0) authentication provider for [Passport](http://passportjs.org/), the Node.js authentication library.
6
+
7
+ The code was originally based on Michael Bosworth's [express-saml](https://github.com/bozzltron/express-saml) library.
8
+
9
+ Passport-SAML has been tested to work with Onelogin, Okta, Shibboleth, [SimpleSAMLphp](http://simplesamlphp.org/) based Identity Providers, and with [Active Directory Federation Services](http://en.wikipedia.org/wiki/Active_Directory_Federation_Services).
10
+
11
+ ## Installation
12
+
13
+ $ npm install passport-saml
14
+
15
+ /
16
+
17
+ ## Usage
18
+
19
+ The examples utilize the [Feide OpenIdp identity provider](https://openidp.feide.no/). You need an account there to log in with this. You also need to [register your site](https://openidp.feide.no/simplesaml/module.php/metaedit/index.php) as a service provider.
20
+
21
+ ### Configure strategy
22
+
23
+ The SAML identity provider will redirect you to the URL provided by the `path` configuration.
24
+
25
+ ```javascript
26
+ const SamlStrategy = require('passport-saml').Strategy;
27
+ [...]
28
+
29
+ passport.use(new SamlStrategy(
30
+ {
31
+ path: '/login/callback',
32
+ entryPoint: 'https://openidp.feide.no/simplesaml/saml2/idp/SSOService.php',
33
+ issuer: 'passport-saml',
34
+ cert: 'fake cert', // cert must be provided
35
+ },
36
+ function(profile, done) {
37
+ findByEmail(profile.email, function(err, user) {
38
+ if (err) {
39
+ return done(err);
40
+ }
41
+ return done(null, user);
42
+ });
43
+ })
44
+ );
45
+ ```
46
+
47
+ ### Configure strategy for multiple providers
48
+
49
+ You can pass a `getSamlOptions` parameter to `MultiSamlStrategy` which will be called before the SAML flows. Passport-SAML will pass in the request object so you can decide which configuation is appropriate.
50
+
51
+ ```javascript
52
+ const { MultiSamlStrategy } = require('passport-saml');
53
+ [...]
54
+
55
+ passport.use(new MultiSamlStrategy(
56
+ {
57
+ passReqToCallback: true, // makes req available in callback
58
+ getSamlOptions: function(request, done) {
59
+ findProvider(request, function(err, provider) {
60
+ if (err) {
61
+ return done(err);
62
+ }
63
+ return done(null, provider.configuration);
64
+ });
65
+ }
66
+ },
67
+ function(req, profile, done) {
68
+ findByEmail(profile.email, function(err, user) {
69
+ if (err) {
70
+ return done(err);
71
+ }
72
+ return done(null, user);
73
+ });
74
+ })
75
+ );
76
+ ```
77
+
78
+ The options passed when the `MultiSamlStrategy` is initialized are also passed as default values to each provider.
79
+ e.g. If you provide an `issuer` on `MultiSamlStrategy`, this will be also a default value for every provider.
80
+ You can override these defaults by passing a new value through the `getSamlOptions` function.
81
+
82
+ Using multiple providers supports `validateInResponseTo`, but all the `InResponse` values are stored on the same Cache. This means, if you're using the default `InMemoryCache`, that all providers have access to it and a provider might get its response validated against another's request. [Issue Report](!https://github.com/node-saml/passport-saml/issues/334). To amend this you should provide a different cache provider per SAML provider, through the `getSamlOptions` function.
83
+
84
+ > :warning: **There's a race condition [bug](https://github.com/node-saml/passport-saml/issues/425) in versions < 1.3.3 which makes it vulnerable to DOS attacks**: Please use > 1.3.3 if you want to use this issue
85
+
86
+ #### The profile object:
87
+
88
+ The profile object referenced above contains the following:
89
+
90
+ ```typescript
91
+ type Profile = {
92
+ issuer?: string;
93
+ sessionIndex?: string;
94
+ nameID?: string;
95
+ nameIDFormat?: string;
96
+ nameQualifier?: string;
97
+ spNameQualifier?: string;
98
+ mail?: string; // InCommon Attribute urn:oid:0.9.2342.19200300.100.1.3
99
+ email?: string; // `mail` if not present in the assertion
100
+ getAssertionXml(): string; // get the raw assertion XML
101
+ getAssertion(): object; // get the assertion XML parsed as a JavaScript object
102
+ getSamlResponseXml(): string; // get the raw SAML response XML
103
+ ID?: string;
104
+ } & {
105
+ [attributeName: string]: unknown; // arbitrary `AttributeValue`s
106
+ };
107
+ ```
108
+
109
+ #### Config parameter details:
110
+
111
+ - **Core**
112
+ - `callbackUrl`: full callbackUrl (overrides path/protocol if supplied)
113
+ - `path`: path to callback; will be combined with protocol and server host information to construct callback url if `callbackUrl` is not specified (default: `/saml/consume`)
114
+ - `protocol`: protocol for callback; will be combined with path and server host information to construct callback url if `callbackUrl` is not specified (default: `http://`)
115
+ - `host`: host for callback; will be combined with path and protocol to construct callback url if `callbackUrl` is not specified (default: `localhost`)
116
+ - `entryPoint`: identity provider entrypoint (is required to be spec-compliant when the request is signed)
117
+ - `issuer`: issuer string to supply to identity provider
118
+ - `audience`: expected saml response Audience (if not provided, Audience won't be verified)
119
+ - `cert`: the IDP's public signing certificate used to validate the signatures of the incoming SAML Responses, see [Security and signatures](#security-and-signatures)
120
+ - `privateKey`: see [Security and signatures](#security-and-signatures).
121
+ - `decryptionPvk`: optional private key that will be used to attempt to decrypt any encrypted assertions that are received
122
+ - `signatureAlgorithm`: optionally set the signature algorithm for signing requests, valid values are 'sha1' (default), 'sha256', or 'sha512'
123
+ - `digestAlgorithm`: optionally set the digest algorithm used to provide a digest for the signed data object, valid values are 'sha1' (default), 'sha256', or 'sha512'
124
+ - `xmlSignatureTransforms`: optionally set an array of signature transforms to be used in HTTP-POST signatures. By default this is `[ 'http://www.w3.org/2000/09/xmldsig#enveloped-signature', 'http://www.w3.org/2001/10/xml-exc-c14n#' ]`
125
+ - **Additional SAML behaviors**
126
+ - `additionalParams`: dictionary of additional query params to add to all requests; if an object with this key is passed to `authenticate`, the dictionary of additional query params will be appended to those present on the returned URL, overriding any specified by initialization options' additional parameters (`additionalParams`, `additionalAuthorizeParams`, and `additionalLogoutParams`)
127
+ - `additionalAuthorizeParams`: dictionary of additional query params to add to 'authorize' requests
128
+ - `identifierFormat`: optional name identifier format to request from identity provider (default: `urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress`)
129
+ - `wantAssertionsSigned`: if truthy, add `WantAssertionsSigned="true"` to the metadata, to specify that the IdP should always sign the assertions.
130
+ - `acceptedClockSkewMs`: Time in milliseconds of skew that is acceptable between client and server when checking `NotBefore` and `NotOnOrAfter` assertion condition validity timestamps. Setting to `-1` will disable checking these conditions entirely. Default is `0`.
131
+ - `maxAssertionAgeMs`: Amount of time after which the framework should consider an assertion expired. If the limit imposed by this variable is stricter than the limit imposed by `NotOnOrAfter`, this limit will be used when determining if an assertion is expired.
132
+ - `attributeConsumingServiceIndex`: optional `AttributeConsumingServiceIndex` attribute to add to AuthnRequest to instruct the IDP which attribute set to attach to the response ([link](http://blog.aniljohn.com/2014/01/data-minimization-front-channel-saml-attribute-requests.html))
133
+ - `disableRequestedAuthnContext`: if truthy, do not request a specific authentication context. This is [known to help when authenticating against Active Directory](https://github.com/node-saml/passport-saml/issues/226) (AD FS) servers.
134
+ - `authnContext`: if truthy, name identifier format to request auth context (default: `urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport`); array of values is also supported
135
+ - `racComparison`: Requested Authentication Context comparison type. Possible values are 'exact','minimum','maximum','better'. Default is 'exact'.
136
+
137
+ - `forceAuthn`: if set to true, the initial SAML request from the service provider specifies that the IdP should force re-authentication of the user, even if they possess a valid session.
138
+ - `providerName`: optional human-readable name of the requester for use by the presenter's user agent or the identity provider
139
+ - `skipRequestCompression`: if set to true, the SAML request from the service provider won't be compressed.
140
+ - `authnRequestBinding`: if set to `HTTP-POST`, will request authentication from IDP via HTTP POST binding, otherwise defaults to HTTP Redirect
141
+ - `disableRequestAcsUrl`: if truthy, SAML AuthnRequest from the service provider will not include the optional AssertionConsumerServiceURL. Default is falsy so it is automatically included.
142
+ - `scoping`: An optional configuration which implements the functionality [explained in the SAML spec paragraph "3.4.1.2 Element <Scoping>"](https://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf). The config object is structured as following:
143
+
144
+ ```javascript
145
+ {
146
+ idpList: [ // optional
147
+ {
148
+ entries: [ // required
149
+ {
150
+ providerId: 'yourProviderId', // required for each entry
151
+ name: 'yourName', // optional
152
+ loc: 'yourLoc', // optional
153
+ }
154
+ ],
155
+ getComplete: 'URI to your complete IDP list', // optional
156
+ },
157
+ ],
158
+ proxyCount: 2, // optional
159
+ requesterId: 'requesterId', // optional
160
+ }
161
+ ```
162
+
163
+ - **InResponseTo Validation**
164
+ - `validateInResponseTo`: if truthy, then InResponseTo will be validated from incoming SAML responses
165
+ - `requestIdExpirationPeriodMs`: Defines the expiration time when a Request ID generated for a SAML request will not be valid if seen in a SAML response in the `InResponseTo` field. Default is 8 hours.
166
+ - `cacheProvider`: Defines the implementation for a cache provider used to store request Ids generated in SAML requests as part of `InResponseTo` validation. Default is a built-in in-memory cache provider. For details see the 'Cache Provider' section.
167
+ - **Issuer Validation**
168
+ - `idpIssuer`: if provided, then the IdP issuer will be validated for incoming Logout Requests/Responses. For ADFS this looks like `https://acme_tools.windows.net/deadbeef`
169
+ - **Passport**
170
+ - `passReqToCallback`: if truthy, `req` will be passed as the first argument to the verify callback (default: `false`)
171
+ - `name`: Optionally, provide a custom name. (default: `saml`). Useful If you want to instantiate the strategy multiple times with different configurations,
172
+ allowing users to authenticate against multiple different SAML targets from the same site. You'll need to use a unique set of URLs
173
+ for each target, and use this custom name when calling `passport.authenticate()` as well.
174
+ - **Logout**
175
+ - `logoutUrl`: base address to call with logout requests (default: `entryPoint`)
176
+ - `additionalLogoutParams`: dictionary of additional query params to add to 'logout' requests
177
+ - `logoutCallbackUrl`: The value with which to populate the `Location` attribute in the `SingleLogoutService` elements in the generated service provider metadata.
178
+
179
+ ### Provide the authentication callback
180
+
181
+ You need to provide a route corresponding to the `path` configuration parameter given to the strategy:
182
+
183
+ The authentication callback must be invoked after the `body-parser` middlerware.
184
+
185
+ ```javascript
186
+ const bodyParser = require("body-parser");
187
+
188
+ app.post(
189
+ "/login/callback",
190
+ bodyParser.urlencoded({ extended: false }),
191
+ passport.authenticate("saml", { failureRedirect: "/", failureFlash: true }),
192
+ function (req, res) {
193
+ res.redirect("/");
194
+ }
195
+ );
196
+ ```
197
+
198
+ ### Authenticate requests
199
+
200
+ Use `passport.authenticate()`, specifying `saml` as the strategy:
201
+
202
+ ```javascript
203
+ app.get(
204
+ "/login",
205
+ passport.authenticate("saml", { failureRedirect: "/", failureFlash: true }),
206
+ function (req, res) {
207
+ res.redirect("/");
208
+ }
209
+ );
210
+ ```
211
+
212
+ ...or, if you wish to add or override query string parameters:
213
+
214
+ ```javascript
215
+ app.get(
216
+ "/login",
217
+ passport.authenticate("saml", {
218
+ additionalParams: { username: "user@domain.com" },
219
+ }),
220
+ function (req, res) {
221
+ res.redirect("/");
222
+ }
223
+ );
224
+ ```
225
+
226
+ ### generateServiceProviderMetadata( decryptionCert, signingCert )
227
+
228
+ As a convenience, the strategy object exposes a `generateServiceProviderMetadata` method which will generate a service provider metadata document suitable for supplying to an identity provider. This method will only work on strategies which are configured with a `callbackUrl` (since the relative path for the callback is not sufficient information to generate a complete metadata document).
229
+
230
+ The `decryptionCert` argument should be a public certificate matching the `decryptionPvk` and is required if the strategy is configured with a `decryptionPvk`.
231
+
232
+ The `signingCert` argument should be a public certificate matching the `privateKey` and is required if the strategy is configured with a `privateKey`.
233
+
234
+ The `generateServiceProviderMetadata` method is also available on the `MultiSamlStrategy`, but needs an extra request and a callback argument (`generateServiceProviderMetadata( req, decryptionCert, signingCert, next )`), which are passed to the `getSamlOptions` to retrieve the correct configuration.
235
+
236
+ ## Security and signatures
237
+
238
+ Passport-SAML uses the HTTP Redirect Binding for its `AuthnRequest`s (unless overridden with the `authnRequestBinding` parameter), and expects to receive the messages back via the HTTP POST binding.
239
+
240
+ Authentication requests sent by Passport-SAML can be signed using RSA signature with SHA1, SHA256 or SHA512 hashing algorithms.
241
+
242
+ To select hashing algorithm, use:
243
+
244
+ ```js
245
+ ...
246
+ signatureAlgorithm: 'sha1' // (default, but not recommended anymore these days)
247
+ signatureAlgorithm: 'sha256', // (preferred - your IDP should support it, otherwise think about upgrading it)
248
+ signatureAlgorithm: 'sha512' // (most secure - check if your IDP supports it)
249
+ ...
250
+ ```
251
+
252
+ To sign them you need to provide a private key in the PEM format via the `privateKey` configuration key.
253
+
254
+ Formats supported for `privateKey` field are,
255
+
256
+ 1. Well formatted PEM:
257
+
258
+ ```
259
+ -----BEGIN PRIVATE KEY-----
260
+ <private key contents here delimited at 64 characters per row>
261
+ -----END PRIVATE KEY-----
262
+
263
+ ```
264
+
265
+ ```
266
+ -----BEGIN RSA PRIVATE KEY-----
267
+ <private key contents here delimited at 64 characters per row>
268
+ -----END RSA PRIVATE KEY-----
269
+
270
+ ```
271
+
272
+ (both versions work)
273
+ See example from tests of the first version of [well formatted private key](test/static/acme_tools_com.key).
274
+
275
+ 2. Alternativelly a single line private key without start/end lines where all rows are joined into single line:
276
+
277
+ See example from tests of [singleline private key](test/static/singleline_acme_tools_com.key).
278
+
279
+ Add it to strategy options like this:
280
+
281
+ ```javascript
282
+ privateKey: fs.readFileSync("./privateKey.pem", "utf-8");
283
+ ```
284
+
285
+ It is a good idea to validate the signatures of the incoming SAML Responses. For this, you can provide the Identity Provider's public PEM-encoded X.509 signing certificate using the `cert` configuration key. The "BEGIN CERTIFICATE" and "END CERTIFICATE" lines should be stripped out and the certificate should be provided on a single line.
286
+
287
+ ```javascript
288
+ cert: "MIICizCCAfQCCQCY8tKaMc0BMjANBgkqh ... W==";
289
+ ```
290
+
291
+ If you have a certificate in the binary DER encoding, you can convert it to the necessary PEM encoding like this:
292
+
293
+ ```bash
294
+ openssl x509 -inform der -in my_certificate.cer -out my_certificate.pem
295
+ ```
296
+
297
+ If the Identity Provider has multiple signing certificates that are valid (such as during the rolling from an old key to a new key and responses signed with either key are valid) then the `cert` configuration key can be an array:
298
+
299
+ ```javascript
300
+ cert: ["MIICizCCAfQCCQCY8tKaMc0BMjANBgkqh ... W==", "MIIEOTCCAyGgAwIBAgIJAKZgJdKdCdL6M ... g="];
301
+ ```
302
+
303
+ The `cert` configuration key can also be a function that receives a callback as argument calls back a possible error and a certificate or array of certificates. This allows the Identity Provider to be polled for valid certificates and the new certificate can be used if it is changed:
304
+
305
+ ```javascript
306
+ cert: function(callback) { callback(null,polledCertificates); }
307
+ ```
308
+
309
+ ## Usage with Active Directory Federation Services
310
+
311
+ Here is a configuration that has been proven to work with ADFS:
312
+
313
+ ```javascript
314
+ {
315
+ entryPoint: 'https://ad.example.net/adfs/ls/',
316
+ issuer: 'https://your-app.example.net/login/callback',
317
+ callbackUrl: 'https://your-app.example.net/login/callback',
318
+ cert: 'MIICizCCAfQCCQCY8tKaMc0BMjANBgkqh ... W==',
319
+ authnContext: 'http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/windows',
320
+ identifierFormat: null
321
+ }
322
+ ```
323
+
324
+ Please note that ADFS needs to have a trust established to your service in order for this to work.
325
+
326
+ For more detailed instructions, see [ADFS documentation](docs/adfs/README.md).
327
+
328
+ ## SAML Response Validation - NotBefore and NotOnOrAfter
329
+
330
+ If the `NotBefore` or the `NotOnOrAfter` attributes are returned in the SAML response, Passport-SAML will validate them
331
+ against the current time +/- a configurable clock skew value. The default for the skew is 0s. This is to account for
332
+ differences between the clock time on the client (Node server with Passport-SAML) and the server (Identity provider).
333
+
334
+ `NotBefore` and `NotOnOrAfter` can be part of either the `SubjectConfirmation` element, or within in the `Assertion/Conditions` element
335
+ in the SAML response.
336
+
337
+ ## Subject confirmation validation
338
+
339
+ When configured (turn `validateInResponseTo` to `true` in the Passport-SAML config), the `InResponseTo` attribute will be validated.
340
+ Validation will succeed if Passport-SAML previously generated a SAML request with an id that matches the value of `InResponseTo`.
341
+
342
+ Also note that `InResponseTo` is validated as an attribute of the top level `Response` element in the SAML response, as well
343
+ as part of the `SubjectConfirmation` element.
344
+
345
+ Previous request id's generated for SAML requests will eventually expire. This is controlled with the `requestIdExpirationPeriodMs` option
346
+ passed into the Passport-SAML config. The default is 28,800,000 ms (8 hours). Once expired, a subsequent SAML response
347
+ received with an `InResponseTo` equal to the expired id will not validate and an error will be returned.
348
+
349
+ ## Cache Provider
350
+
351
+ When `InResponseTo` validation is turned on, Passport-SAML will store generated request ids used in SAML requests to the IdP. The implementation
352
+ of how things are stored, checked to see if they exist, and eventually removed is from the Cache Provider used by Passport-SAML.
353
+
354
+ The default implementation is a simple in-memory cache provider. For multiple server/process scenarios, this will not be sufficient as
355
+ the server/process that generated the request id and stored in memory could be different than the server/process handling the
356
+ SAML response. The `InResponseTo` could fail in this case erroneously.
357
+
358
+ To support this scenario you can provide an implementation for a cache provider by providing an object with following functions:
359
+
360
+ ```javascript
361
+ {
362
+ saveAsync: async function(key, value) {
363
+ // saves the key with the optional value, returns the saved value
364
+ },
365
+ getAsync: async function(key) {
366
+ // returns the value if found, null otherwise
367
+ },
368
+ removeAsync: async function(key) {
369
+ // removes the key from the cache, returns the
370
+ // key removed, null if no key is removed
371
+ }
372
+ }
373
+ ```
374
+
375
+ Provide an instance of an object which has these functions passed to the `cacheProvider` config option when using Passport-SAML.
376
+
377
+ ## SLO (single logout)
378
+
379
+ Passport-SAML has built in support for SLO including
380
+
381
+ - Signature validation
382
+ - IdP initiated and SP initiated logouts
383
+ - Decryption of encrypted name identifiers in IdP initiated logout
384
+ - `Redirect` and `POST` SAML Protocol Bindings
385
+
386
+ ## ChangeLog
387
+
388
+ See [Releases](https://github.com/node-saml/passport-saml/releases) to find the changes that go into each release.
389
+
390
+ ## FAQ
391
+
392
+ ### Is there an example I can look at?
393
+
394
+ Gerard Braad has provided an example app at https://github.com/gbraad/passport-saml-example/
395
+
396
+ ## Node Support Policy
397
+
398
+ We only support [Long-Term Support](https://github.com/nodejs/Release) versions of Node.
399
+
400
+ We specifically limit our support to LTS versions of Node, not because this package won't work on other versions, but because we have a limited amount of time, and supporting LTS offers the greatest return on that investment.
401
+
402
+ It's possible this package will work correctly on newer versions of Node. It may even be possible to use this package on older versions of Node, though that's more unlikely as we'll make every effort to take advantage of features available in the oldest LTS version we support.
403
+
404
+ As each Node LTS version reaches its end-of-life we will remove that version from the `node` `engines` property of our package's `package.json` file. Removing a Node version is considered a breaking change and will entail the publishing of a new major version of this package. We will not accept any requests to support an end-of-life version of Node. Any merge requests or issues supporting an end-of-life version of Node will be closed.
405
+
406
+ We will accept code that allows this package to run on newer, non-LTS, versions of Node.
@@ -0,0 +1,5 @@
1
+ /// <reference types="node" />
2
+ import * as crypto from "crypto";
3
+ export declare function getSigningAlgorithm(shortName?: string): string;
4
+ export declare function getDigestAlgorithm(shortName?: string): string;
5
+ export declare function getSigner(shortName?: string): crypto.Signer;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSigner = exports.getDigestAlgorithm = exports.getSigningAlgorithm = void 0;
4
+ const crypto = require("crypto");
5
+ function getSigningAlgorithm(shortName) {
6
+ switch (shortName) {
7
+ case "sha256":
8
+ return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
9
+ case "sha512":
10
+ return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512";
11
+ case "sha1":
12
+ default:
13
+ return "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
14
+ }
15
+ }
16
+ exports.getSigningAlgorithm = getSigningAlgorithm;
17
+ function getDigestAlgorithm(shortName) {
18
+ switch (shortName) {
19
+ case "sha256":
20
+ return "http://www.w3.org/2001/04/xmlenc#sha256";
21
+ case "sha512":
22
+ return "http://www.w3.org/2001/04/xmlenc#sha512";
23
+ case "sha1":
24
+ default:
25
+ return "http://www.w3.org/2000/09/xmldsig#sha1";
26
+ }
27
+ }
28
+ exports.getDigestAlgorithm = getDigestAlgorithm;
29
+ function getSigner(shortName) {
30
+ switch (shortName) {
31
+ case "sha256":
32
+ return crypto.createSign("RSA-SHA256");
33
+ case "sha512":
34
+ return crypto.createSign("RSA-SHA512");
35
+ case "sha1":
36
+ default:
37
+ return crypto.createSign("RSA-SHA1");
38
+ }
39
+ }
40
+ exports.getSigner = getSigner;
41
+ //# sourceMappingURL=algorithms.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"algorithms.js","sourceRoot":"","sources":["../../src/node-saml/algorithms.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC,SAAgB,mBAAmB,CAAC,SAAkB;IACpD,QAAQ,SAAS,EAAE;QACjB,KAAK,QAAQ;YACX,OAAO,mDAAmD,CAAC;QAC7D,KAAK,QAAQ;YACX,OAAO,mDAAmD,CAAC;QAC7D,KAAK,MAAM,CAAC;QACZ;YACE,OAAO,4CAA4C,CAAC;KACvD;AACH,CAAC;AAVD,kDAUC;AAED,SAAgB,kBAAkB,CAAC,SAAkB;IACnD,QAAQ,SAAS,EAAE;QACjB,KAAK,QAAQ;YACX,OAAO,yCAAyC,CAAC;QACnD,KAAK,QAAQ;YACX,OAAO,yCAAyC,CAAC;QACnD,KAAK,MAAM,CAAC;QACZ;YACE,OAAO,wCAAwC,CAAC;KACnD;AACH,CAAC;AAVD,gDAUC;AAED,SAAgB,SAAS,CAAC,SAAkB;IAC1C,QAAQ,SAAS,EAAE;QACjB,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;QACzC,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;QACzC,KAAK,MAAM,CAAC;QACZ;YACE,OAAO,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;KACxC;AACH,CAAC;AAVD,8BAUC","sourcesContent":["import * as crypto from \"crypto\";\n\nexport function getSigningAlgorithm(shortName?: string): string {\n switch (shortName) {\n case \"sha256\":\n return \"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256\";\n case \"sha512\":\n return \"http://www.w3.org/2001/04/xmldsig-more#rsa-sha512\";\n case \"sha1\":\n default:\n return \"http://www.w3.org/2000/09/xmldsig#rsa-sha1\";\n }\n}\n\nexport function getDigestAlgorithm(shortName?: string): string {\n switch (shortName) {\n case \"sha256\":\n return \"http://www.w3.org/2001/04/xmlenc#sha256\";\n case \"sha512\":\n return \"http://www.w3.org/2001/04/xmlenc#sha512\";\n case \"sha1\":\n default:\n return \"http://www.w3.org/2000/09/xmldsig#sha1\";\n }\n}\n\nexport function getSigner(shortName?: string): crypto.Signer {\n switch (shortName) {\n case \"sha256\":\n return crypto.createSign(\"RSA-SHA256\");\n case \"sha512\":\n return crypto.createSign(\"RSA-SHA512\");\n case \"sha1\":\n default:\n return crypto.createSign(\"RSA-SHA1\");\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { CacheItem, CacheProvider } from "./inmemory-cache-provider";
2
+ import { SAML } from "./saml";
3
+ export { SAML, CacheItem, CacheProvider };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SAML = void 0;
4
+ const saml_1 = require("./saml");
5
+ Object.defineProperty(exports, "SAML", { enumerable: true, get: function () { return saml_1.SAML; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node-saml/index.ts"],"names":[],"mappings":";;;AACA,iCAA8B;AAErB,qFAFA,WAAI,OAEA","sourcesContent":["import type { CacheItem, CacheProvider } from \"./inmemory-cache-provider\";\nimport { SAML } from \"./saml\";\n\nexport { SAML, CacheItem, CacheProvider };\n"]}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Simple in memory cache provider. To be used to store state of requests that needs
3
+ * to be validated/checked when a response is received.
4
+ *
5
+ * This is the default implementation of a cache provider used by Passport-SAML. For
6
+ * multiple server instances/load balanced scenarios (I.e. the SAML request could have
7
+ * been generated from a different server/process handling the SAML response) this
8
+ * implementation will NOT be sufficient.
9
+ *
10
+ * The caller should provide their own implementation for a cache provider as defined
11
+ * in the config options for Passport-SAML.
12
+ * @param options
13
+ * @constructor
14
+ */
15
+ export interface CacheItem {
16
+ value: string;
17
+ createdAt: number;
18
+ }
19
+ interface CacheProviderOptions {
20
+ keyExpirationPeriodMs: number;
21
+ }
22
+ export declare class CacheProvider {
23
+ cacheKeys: Record<string, CacheItem>;
24
+ options: CacheProviderOptions;
25
+ constructor(options: Partial<CacheProviderOptions>);
26
+ /**
27
+ * Store an item in the cache, using the specified key and value.
28
+ * Internally will keep track of the time the item was added to the cache
29
+ * @param id
30
+ * @param value
31
+ */
32
+ saveAsync(key: string, value: string): Promise<CacheItem | null>;
33
+ /**
34
+ * Returns the value of the specified key in the cache
35
+ * @param id
36
+ * @returns {boolean}
37
+ */
38
+ getAsync(key: string): Promise<string | null>;
39
+ /**
40
+ * Removes an item from the cache if it exists
41
+ * @param key
42
+ */
43
+ removeAsync(key: string): Promise<string | null>;
44
+ }
45
+ export {};