Skip to content

Commit 7d81c85

Browse files
committed
1 parent d7e3087 commit 7d81c85

2 files changed

Lines changed: 76 additions & 2 deletions

File tree

‎spec/vulnerabilities.spec.js‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12768,4 +12768,78 @@ describe('Vulnerabilities', () => {
1276812768
});
1276912769
});
1277012770
});
12771+
12772+
describe('(GHSA-9492-427f-466x) Email address format validation backtracks on a crafted email address', () => {
12773+
const headers = {
12774+
'X-Parse-Application-Id': 'test',
12775+
'X-Parse-REST-API-Key': 'rest',
12776+
'Content-Type': 'application/json',
12777+
};
12778+
const lineTerminators = {
12779+
LF: '\n',
12780+
CR: '\r',
12781+
LS: String.fromCharCode(0x2028),
12782+
PS: String.fromCharCode(0x2029),
12783+
};
12784+
const craftedEmail = lineTerminator => '@'.repeat(100000) + lineTerminator;
12785+
const signUp = body =>
12786+
request({
12787+
method: 'POST',
12788+
url: `${Parse.serverURL}/users`,
12789+
headers,
12790+
body: JSON.stringify(body),
12791+
}).catch(e => e);
12792+
12793+
for (const [name, lineTerminator] of Object.entries(lineTerminators)) {
12794+
it(`rejects a crafted email address ending with ${name} on sign-up in time`, async () => {
12795+
const start = Date.now();
12796+
const response = await signUp({
12797+
username: 'user',
12798+
password: 'password',
12799+
email: craftedEmail(lineTerminator),
12800+
});
12801+
expect(Date.now() - start).toBeLessThan(2000);
12802+
expect(response.data.code).toBe(Parse.Error.INVALID_EMAIL_ADDRESS);
12803+
});
12804+
}
12805+
12806+
it('rejects a crafted email address on user update in time', async () => {
12807+
const user = await Parse.User.signUp('user', 'password');
12808+
const start = Date.now();
12809+
const response = await request({
12810+
method: 'PUT',
12811+
url: `${Parse.serverURL}/users/${user.id}`,
12812+
headers: { ...headers, 'X-Parse-Session-Token': user.getSessionToken() },
12813+
body: JSON.stringify({ email: craftedEmail(lineTerminators.LF) }),
12814+
}).catch(e => e);
12815+
expect(Date.now() - start).toBeLessThan(2000);
12816+
expect(response.data.code).toBe(Parse.Error.INVALID_EMAIL_ADDRESS);
12817+
});
12818+
12819+
it('accepts an email address with a character before and after an at sign', async () => {
12820+
const emails = ['user@example.com', 'a@b', 'a @ b', 'a@b@c', 'a@@b', '@a@b'];
12821+
for (const [i, email] of emails.entries()) {
12822+
const response = await signUp({ username: `user${i}`, password: 'password', email });
12823+
expect(response.status).withContext(email).toBe(201);
12824+
}
12825+
});
12826+
12827+
it('rejects an email address without a character before or after an at sign', async () => {
12828+
for (const email of ['example.com', '@example.com', 'user@', '@', '@@']) {
12829+
const response = await signUp({ username: 'user', password: 'password', email });
12830+
expect(response.data.code).withContext(email).toBe(Parse.Error.INVALID_EMAIL_ADDRESS);
12831+
}
12832+
});
12833+
12834+
it('rejects an email address with a line terminator', async () => {
12835+
for (const lt of Object.values(lineTerminators)) {
12836+
for (const email of [`${lt}a@b`, `a${lt}@b`, `a@${lt}b`, `a@b${lt}`]) {
12837+
const response = await signUp({ username: 'user', password: 'password', email });
12838+
expect(response.data.code)
12839+
.withContext(encodeURIComponent(email))
12840+
.toBe(Parse.Error.INVALID_EMAIL_ADDRESS);
12841+
}
12842+
}
12843+
});
12844+
});
1277112845
});

‎src/RestWrite.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,8 @@ RestWrite.prototype._validateEmail = function () {
10021002
if (!this.data.email || this.data.email.__op === 'Delete') {
10031003
return Promise.resolve();
10041004
}
1005-
// Validate basic email address format
1006-
if (!this.data.email.match(/^.+@.+$/)) {
1005+
// Validate basic email address format in linear time
1006+
if (!this.data.email.match(/^.[^@\n\r\u2028\u2029]*@.+$/)) {
10071007
return Promise.reject(
10081008
new Parse.Error(Parse.Error.INVALID_EMAIL_ADDRESS, 'Email address format is invalid.')
10091009
);

0 commit comments

Comments
 (0)