Skip to content

Commit

Permalink
Hyperlink Injection in People Invitation Emails (#2307)
Browse files Browse the repository at this point in the history
* Strip special characters

* Allow hyphens
  • Loading branch information
sjaanus committed Nov 1, 2022
1 parent f1634bb commit c501fb2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/lib/services/email-service.test.ts
Expand Up @@ -80,3 +80,24 @@ test('Can supply additional SMTP transport options', async () => {
},
});
});

test('should strip special characters from email subject', async () => {
const emailService = new EmailService(
{
host: 'test',
port: 9999,
secure: false,
sender: 'noreply@getunleash.ai',
smtpuser: '',
smtppass: '',
},
noLoggerProvider,
);
expect(emailService.stripSpecialCharacters('http://evil.com')).toBe(
'httpevilcom',
);
expect(emailService.stripSpecialCharacters('http://ööbik.com')).toBe(
'httpööbikcom',
);
expect(emailService.stripSpecialCharacters('tom-jones')).toBe('tom-jones');
});
11 changes: 10 additions & 1 deletion src/lib/services/email-service.ts
Expand Up @@ -138,7 +138,12 @@ export class EmailService {
): Promise<IEmailEnvelope> {
if (this.configured()) {
const year = new Date().getFullYear();
const context = { passwordLink, name, year, unleashUrl };
const context = {
passwordLink,
name: this.stripSpecialCharacters(name),
year,
unleashUrl,
};
const bodyHtml = await this.compileTemplate(
'getting-started',
TemplateFormat.HTML,
Expand Down Expand Up @@ -222,4 +227,8 @@ export class EmailService {
configured(): boolean {
return this.sender !== 'not-configured' && this.mailer !== undefined;
}

stripSpecialCharacters(str: string): string {
return str?.replace(/[`~!@#$%^&*()_|+=?;:'",.<>\{\}\[\]\\\/]/gi, '');
}
}

0 comments on commit c501fb2

Please sign in to comment.