Skip to content

Commit 79ae557

Browse files
author
Steve Hobbs
authored
Merge pull request from GHSA-7ww6-75fj-jcj7
* Sanitize additional signup fields using DOMPurify * Remove HTML entirely from additionalSignupFields
1 parent 7280665 commit 79ae557

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

src/__tests__/connection/database/actions.test.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,75 @@ describe('database/actions.js', () => {
137137
expect(signUpMock.calls.length).toBe(1);
138138
expect(signUpMock.calls[0][0]).toBe(id);
139139
});
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&Tab;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+
});
140211
});

src/connection/database/actions.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import Immutable, { Map } from 'immutable';
21
import { getEntity, read, swap, updateEntity } from '../../store/index';
32
import webApi from '../../core/web_api';
43
import { closeLock, logIn as coreLogIn, logInSuccess, validateAndSubmit } from '../../core/actions';
54
import * as l from '../../core/index';
65
import * as c from '../../field/index';
6+
import { sanitize } from 'dompurify';
7+
78
import {
89
databaseConnection,
910
databaseConnectionName,
@@ -107,7 +108,8 @@ export function signUp(id) {
107108
additionalSignUpFields(m).forEach(x => {
108109
const storage = x.get('storage');
109110
const fieldName = x.get('name');
110-
const fieldValue = c.getFieldValue(m, x.get('name'));
111+
const fieldValue = sanitize(c.getFieldValue(m, x.get('name')), { ALLOWED_TAGS: [] });
112+
111113
switch (storage) {
112114
case 'root':
113115
params[fieldName] = fieldValue;

0 commit comments

Comments
 (0)