Skip to content

Commit

Permalink
PSW-22 Sanitize names on account patch (#4821)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedwiper committed Mar 15, 2024
1 parent 4b9b80a commit d52e547
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,24 @@ describe('Account Controller (API)', () => {
.send(params)
.expect(400);
});

it('should strip HTML off of firstName and lastName', async () => {
currentUser = mapUserToCurrentUser(teacherUser, teacherAccount);
const params: PatchMyAccountParams = {
passwordOld: defaultPassword,
firstName: 'Jane<script>alert("XSS")</script>',
lastName: '<b>Doe</b>',
};

await request(app.getHttpServer()) //
.patch(`${basePath}/me`)
.send(params)
.expect(200);

const updatedUser = await em.findOneOrFail(User, teacherUser.id);
expect(updatedUser.firstName).toEqual('Jane');
expect(updatedUser.lastName).toEqual('Doe');
});
});

describe('[GET]', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { PrivacyProtect } from '@shared/controller';
import { PrivacyProtect, SanitizeHtml } from '@shared/controller';
import { IsEmail, IsOptional, IsString, Matches } from 'class-validator';
import { passwordPattern } from './password-pattern';

Expand Down Expand Up @@ -34,6 +34,7 @@ export class PatchMyAccountParams {

@IsString()
@IsOptional()
@SanitizeHtml()
@ApiProperty({
description: 'The new first name for the current user.',
required: false,
Expand All @@ -43,6 +44,7 @@ export class PatchMyAccountParams {

@IsString()
@IsOptional()
@SanitizeHtml()
@ApiProperty({
description: 'The new last name for the current user.',
required: false,
Expand Down

0 comments on commit d52e547

Please sign in to comment.