Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/backend/src/api/routes/dos-org-sync.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export class DosOrgSyncWebhookController {
@Body() payload: DosOrgSyncDto,
@Headers('x-dos-signature') signature?: string
) {
const rawBody = typeof req.body === 'string' ? req.body : JSON.stringify(payload);
const rawBody =
(req as any).rawBody ||
(typeof req.body === 'string' ? req.body : JSON.stringify(payload));
Comment on lines +65 to +67

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When falling back to stringifying the parsed body, using req.body is more reliable than payload. payload is the validated and transformed DTO instance, which may have properties stripped (if whitelist: true is enabled in the global ValidationPipe) or transformed by class-transformer. Using req.body ensures that the fallback stringification is as close to the original request payload as possible.

Suggested change
const rawBody =
(req as any).rawBody ||
(typeof req.body === 'string' ? req.body : JSON.stringify(payload));
const rawBody =
(req as any).rawBody ||
(typeof req.body === 'string' ? req.body : JSON.stringify(req.body));

if (!this.verifySignature(rawBody, signature)) {
throw new HttpException('Invalid webhook signature', HttpStatus.UNAUTHORIZED);
}
Expand Down
13 changes: 9 additions & 4 deletions libraries/nestjs-libraries/src/dtos/webhooks/dos-org-sync.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export enum DosSyncEvent {

export class DosOrgSyncDataDto {
@IsString()
@IsNotEmpty()
org_id: string;
@IsOptional()
org_id?: string;

@IsString()
@IsOptional()
Expand All @@ -52,16 +52,21 @@ export class DosOrgSyncDataDto {
}

export class DosOrgSyncDto {
@IsString()
@IsOptional()
id?: string;

@IsString()
@IsNotEmpty()
event: DosSyncEvent;
event: string;

@IsString()
@IsOptional()
timestamp?: string;

@IsObject()
@IsOptional()
@ValidateNested()
@Type(() => DosOrgSyncDataDto)
data: DosOrgSyncDataDto;
data?: DosOrgSyncDataDto;
}
Loading