Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

fix: jwt bypass

Nevo Davida5affe62c74e
diff --git a/apps/backend/src/api/routes/enterprise.controller.ts b/apps/backend/src/api/routes/enterprise.controller.ts
index c14eebdb5..fef89ef8e 100644
--- a/apps/backend/src/api/routes/enterprise.controller.ts
+++ b/apps/backend/src/api/routes/enterprise.controller.ts
@@ -71,7 +71,13 @@ export class EnterpriseController {
webhookUrl: string;
}>(params);
- if (!load || !load.redirectUrl || !load.apiKey || !load.provider) {
+ if (
+ !load ||
+ !load.redirectUrl ||
+ !load.apiKey ||
+ typeof load.apiKey !== 'string' ||
+ !load.provider
+ ) {
return;
}
@@ -117,7 +123,13 @@ export class EnterpriseController {
id: string;
}>(params);
- if (!load || !load.apiKey || !load.id) {
+ if (
+ !load ||
+ !load.apiKey ||
+ !load.id ||
+ typeof load.apiKey !== 'string' ||
+ typeof load.id !== 'string'
+ ) {
return { success: false };
}
diff --git a/apps/backend/src/api/routes/no.auth.integrations.controller.ts b/apps/backend/src/api/routes/no.auth.integrations.controller.ts
index 8d247af45..0c0df0c29 100644
--- a/apps/backend/src/api/routes/no.auth.integrations.controller.ts
+++ b/apps/backend/src/api/routes/no.auth.integrations.controller.ts
@@ -377,7 +377,18 @@ export class NoAuthIntegrationsController {
}
const { integrationId, organizationId, internalId, provider } = payload;
- if (!integrationId || !organizationId || !internalId || !provider) {
+ if (
+ !integrationId ||
+ typeof integrationId !== 'string' ||
+ !organizationId ||
+ typeof organizationId !== 'string' ||
+ !internalId ||
+ typeof internalId !== 'string' ||
+ !provider ||
+ typeof provider !== 'string' ||
+ 'timeLimit' in payload || // team invite token
+ 'expires' in payload // password reset token
+ ) {
throw new HttpException('Invalid token payload', 400);
}
@@ -385,7 +396,11 @@ export class NoAuthIntegrationsController {
organizationId,
integrationId
);
- if (!integration || integration.internalId !== internalId) {
+ if (
+ !integration ||
+ integration.internalId !== internalId ||
+ integration.providerIdentifier !== provider
+ ) {
throw new HttpException('Integration not found', 404);
}
@@ -428,8 +443,10 @@ export class NoAuthIntegrationsController {
false,
undefined,
undefined,
- AuthService.signJWT(
- JSON.parse(Buffer.from(body.cookies, 'base64').toString())
+ // stored encrypted like connectSocialMedia does, never signed: the
+ // cookies JSON comes from the request
+ AuthService.fixedEncryption(
+ Buffer.from(body.cookies, 'base64').toString()
)
);
diff --git a/apps/backend/src/api/routes/public.controller.ts b/apps/backend/src/api/routes/public.controller.ts
index 157487d45..554edd8a1 100644
--- a/apps/backend/src/api/routes/public.controller.ts
+++ b/apps/backend/src/api/routes/public.controller.ts
@@ -123,7 +123,16 @@ export class PublicController {
billing: 'FREE' | 'STANDARD' | 'TEAM' | 'PRO' | 'ULTIMATE';
};
- if (!load || !load.orgId || !load.billing || !pricing[load.billing]) {
+ if (
+ !load ||
+ !load.orgId ||
+ typeof load.orgId !== 'string' ||
+ !load.billing ||
+ !pricing[load.billing] ||
+ 'timeLimit' in load || // team invite token
+ 'providerName' in load || // login token (full User row)
+ 'expires' in load // password reset token
+ ) {
return { success: false };
}
diff --git a/apps/backend/src/services/auth/auth.middleware.ts b/apps/backend/src/services/auth/auth.middleware.ts
index dc7213dde..f2a7056cc 100644
--- a/apps/backend/src/services/auth/auth.middleware.ts
+++ b/apps/backend/src/services/auth/auth.middleware.ts
@@ -43,7 +43,7 @@ export class AuthMiddleware implements NestMiddleware {
const payload = AuthService.verifyJWT(auth) as User | null;
const orgHeader = req.cookies.showorg || req.headers.showorg;
- if (!payload?.id) {
+ if (!payload?.id || typeof payload.id !== 'string') {
throw new HttpForbiddenException();
}
diff --git a/apps/backend/src/services/auth/auth.service.ts b/apps/backend/src/services/auth/auth.service.ts
index d52c553ec..89706de39 100644
--- a/apps/backend/src/services/auth/auth.service.ts
+++ b/apps/backend/src/services/auth/auth.service.ts
@@ -116,7 +116,13 @@ export class AuthService {
try {
const getOrg: any = AuthChecker.verifyJWT(cookie);
- if (dayjs(getOrg.timeLimit).isBefore(dayjs())) {
+ if (
+ typeof getOrg.orgId !== 'string' ||
+ typeof getOrg.id !== 'string' ||
+ !['USER', 'ADMIN'].includes(getOrg.role) ||
+ !getOrg.timeLimit ||
+ dayjs(getOrg.timeLimit).isBefore(dayjs())
+ ) {
return false;
}
@@ -234,7 +240,7 @@ export class AuthService {
id: string;
expires: string;
};
- if (dayjs(user.expires).isBefore(dayjs())) {
+ if (typeof user.id !== 'string' || dayjs(user.expires).isBefore(dayjs())) {
return false;
}
diff --git a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts
index 0201a18a9..01cb287dc 100644
--- a/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/integrations/integration.repository.ts
@@ -467,6 +467,9 @@ export class IntegrationRepository {
updateNameAndUrl(id: string, name: string, url: string) {
return this._integration.model.integration.update({
+ select: {
+ id: true,
+ },
where: {
id,
},
@@ -539,6 +542,9 @@ export class IntegrationRepository {
}));
return this._integration.model.integration.update({
+ select: {
+ id: true,
+ },
where: {
id,
organizationId: org,
@@ -557,6 +563,9 @@ export class IntegrationRepository {
updateIntegrationGroup(org: string, id: string, group: string) {
return this._integration.model.integration.update({
+ select: {
+ id: true,
+ },
where: {
id,
organizationId: org,
diff --git a/libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts b/libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts
index c6cf15bf0..b14f5db69 100644
--- a/libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/organizations/organization.service.ts
@@ -103,9 +103,16 @@ export class OrganizationService {
async inviteTeamMember(org: Organization, user: User, body: AddTeamMemberDto) {
const timeLimit = dayjs().add(2, 'day').format('YYYY-MM-DD HH:mm:ss');
const id = makeId(5);
+ // only the invite fields, the body can carry undeclared properties
const url =
process.env.FRONTEND_URL +
- `/?org=${AuthService.signJWT({ ...body, orgId: org.id, timeLimit, id })}`;
+ `/?org=${AuthService.signJWT({
+ email: body.email,
+ role: body.role,
+ orgId: org.id,
+ timeLimit,
+ id,
+ })}`;
if (body.sendEmail) {
const inviter = user.name
? `${user.name} (${user.email})`