Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
🐛 Validate domain name
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 15, 2020
1 parent c3dcb4a commit 3c64599
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/errors/errors.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const CURSOR_PIPE_FORMAT = '400015: Invalid cursor format';
export const EMAIL_DELETE_PRIMARY = '400016: Cannot delete primary email';
export const CANNOT_UPDATE_ROLE_SOLE_OWNER =
'400017: Cannot change the role of the only owner';
export const INVALID_DOMAIN = '400018: Invalid domain';

export const EMAIL_USER_CONFLICT =
'409001: User with this email already exists';
Expand Down
15 changes: 12 additions & 3 deletions src/modules/domains/domains.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import {
domainsWhereUniqueInput,
} from '@prisma/client';
import got from 'got';
import { URL } from 'url';
import {
DOMAIN_NOT_FOUND,
DOMAIN_NOT_VERIFIED,
INVALID_DOMAIN,
UNAUTHORIZED_RESOURCE,
} from '../../errors/errors.constants';
import { URL } from 'url';
import { DnsService } from '../../providers/dns/dns.service';
import { Expose } from '../../providers/prisma/prisma.interface';
import { PrismaService } from '../../providers/prisma/prisma.service';
Expand All @@ -39,8 +40,16 @@ export class DomainsService {
groupId: number,
data: Omit<Omit<domainsCreateInput, 'group'>, 'verificationCode'>,
): Promise<domains> {
const fullUrl = new URL(data.domain);
data.domain = fullUrl.hostname;
try {
const fullUrl = new URL(data.domain);
data.domain = fullUrl.hostname;
} catch (error) {}
if (
!/(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/.test(
data.domain,
)
)
throw new BadRequestException(INVALID_DOMAIN);
const verificationCode = this.tokensService.generateUuid();
const currentProfilePicture = await this.prisma.groups.findOne({
where: { id: groupId },
Expand Down

0 comments on commit 3c64599

Please sign in to comment.