@@ -137,4 +137,75 @@ describe('database/actions.js', () => {
137
137
expect ( signUpMock . calls . length ) . toBe ( 1 ) ;
138
138
expect ( signUpMock . calls [ 0 ] [ 0 ] ) . toBe ( id ) ;
139
139
} ) ;
140
+
141
+ it ( 'sanitizes additionalSignUp fields using dompurify' , ( ) => {
142
+ const id = 1 ;
143
+ const hookRunner = jest . fn ( ( str , m , context , fn ) => fn ( ) ) ;
144
+
145
+ require ( 'connection/database/index' ) . databaseConnectionName = ( ) => 'test-connection' ;
146
+ require ( 'connection/database/index' ) . shouldAutoLogin = ( ) => true ;
147
+
148
+ // Test different fields using some examples from DOMPurify
149
+ // https://github.com/cure53/DOMPurify#some-purification-samples-please
150
+ const m = Immutable . fromJS ( {
151
+ field : {
152
+ email : {
153
+ value : 'test@email.com'
154
+ } ,
155
+ password : {
156
+ value : 'testpass'
157
+ } ,
158
+ family_name : {
159
+ value : 'Test <a href="https://www.google.co.uk">Fake link</a>' // HTML but not malicious
160
+ } ,
161
+ given_name : {
162
+ value : '<img src=x onerror=alert(1)//>'
163
+ } ,
164
+ name : {
165
+ value : '<p>abc<iframe//src=jAva	script:alert(3)>def</p>'
166
+ } ,
167
+ other_name : {
168
+ value :
169
+ '<div onclick=alert(0)><form onsubmit=alert(1)><input onfocus=alert(2) name=parentNode>123</form></div>'
170
+ }
171
+ } ,
172
+ database : {
173
+ additionalSignUpFields : [
174
+ { name : 'family_name' , storage : 'root' } ,
175
+ { name : 'given_name' , storage : 'root' } ,
176
+ { name : 'name' , storage : 'root' } ,
177
+ { name : 'other_name' }
178
+ ]
179
+ } ,
180
+ core : {
181
+ hookRunner
182
+ }
183
+ } ) ;
184
+
185
+ swap ( setEntity , 'lock' , id , m ) ;
186
+ signUp ( id ) ;
187
+
188
+ const {
189
+ validateAndSubmit : { mock : validateAndSubmitMock }
190
+ } = coreActionsMock ( ) ;
191
+
192
+ validateAndSubmitMock . calls [ 0 ] [ 2 ] ( m ) ;
193
+
194
+ const {
195
+ signUp : { mock : signUpMock }
196
+ } = webApiMock ( ) ;
197
+
198
+ expect ( signUpMock . calls [ 0 ] [ 1 ] ) . toMatchObject ( {
199
+ connection : 'test-connection' ,
200
+ email : 'test@email.com' ,
201
+ password : 'testpass' ,
202
+ autoLogin : true ,
203
+ family_name : 'Test Fake link' ,
204
+ given_name : '' ,
205
+ name : 'abc' ,
206
+ user_metadata : {
207
+ other_name : '123'
208
+ }
209
+ } ) ;
210
+ } ) ;
140
211
} ) ;
0 commit comments