@@ -9,6 +9,7 @@ var querystring = require('querystring');
9
9
var SignedXml = require ( 'xml-crypto' ) . SignedXml ;
10
10
var templates = require ( './templates' ) ;
11
11
var EventEmitter = require ( 'events' ) ;
12
+ var validUrl = require ( 'valid-url' ) ;
12
13
13
14
var utils = require ( './utils' ) ;
14
15
var AuthenticationFailedError = require ( './errors/AuthenticationFailedError' ) ;
@@ -109,11 +110,16 @@ Samlp.prototype = {
109
110
getSamlRequestParams : function ( opts , callback ) {
110
111
var options = xtend ( opts || { } , this . options ) ;
111
112
113
+ var idpUrl = options . identityProviderUrl ;
114
+ if ( typeof idpUrl !== 'string' || ! validUrl . isWebUri ( idpUrl ) ) {
115
+ return callback ( new Error ( `Invalid identity provider URL: ${ JSON . stringify ( idpUrl ) } ` ) ) ;
116
+ }
117
+
112
118
var signatureAlgorithm = options . signatureAlgorithm || 'rsa-sha256' ;
113
119
var digestAlgorithm = options . digestAlgorithm || 'sha256' ;
114
120
115
121
var assert_and_destination = templates . assert_and_destination ( {
116
- Destination : options . identityProviderUrl ,
122
+ Destination : idpUrl ,
117
123
AssertionConsumerServiceURL : options . callback
118
124
} ) ;
119
125
@@ -133,7 +139,7 @@ Samlp.prototype = {
133
139
}
134
140
135
141
var SAMLRequest = trimXml ( ! options . requestTemplate ? templates . samlrequest ( model ) : supplant ( options . requestTemplate , model ) ) ;
136
- var parsedUrl = url . parse ( options . identityProviderUrl , true ) ;
142
+ var parsedUrl = url . parse ( idpUrl , true ) ;
137
143
var params = {
138
144
SAMLRequest : null ,
139
145
RelayState : options . RelayState || ( parsedUrl . query && parsedUrl . query . RelayState ) || ''
@@ -196,15 +202,10 @@ Samlp.prototype = {
196
202
getSamlRequestUrl : function ( opts , callback ) {
197
203
var options = xtend ( opts || { } , this . options ) ;
198
204
199
- if ( ! options . identityProviderUrl ) {
200
- return callback ( new Error ( 'Missing value for the identity provider login URL' ) ) ;
201
- }
202
-
203
- var parsedUrl = url . parse ( options . identityProviderUrl , true ) ;
204
-
205
205
this . getSamlRequestParams ( options , function ( err , params ) {
206
206
if ( err ) return callback ( err ) ;
207
207
208
+ var parsedUrl = url . parse ( options . identityProviderUrl , true ) ;
208
209
var samlRequestUrl = options . identityProviderUrl . split ( '?' ) [ 0 ] + '?' + qs . encode ( xtend ( parsedUrl . query , params ) ) ;
209
210
return callback ( null , samlRequestUrl ) ;
210
211
} ) ;
0 commit comments