Skip to content

Commit

Permalink
fix(backend): update security rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Sep 17, 2024
1 parent 4eced63 commit 13eb884
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 30 deletions.
2 changes: 0 additions & 2 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
"license": "MIT",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"db:dev:data-anonymize": "npx ts-node -r tsconfig-paths/register --transpile-only src/run-data-anonymization.ts | pino-pretty --singleLine",
"db:dev:generate": "typeorm-ts-node-commonjs migration:generate ./src/_migrations/auto-migration -d ./src/database/services/_postgres/PG_MIGRATION_CONFIG.const.ts",
"db:dev:migrate-down:last": "npx ts-node -r tsconfig-paths/register --transpile-only src/run-migrate-down-last.ts",
"db:dev:migrate-redo": "npx ts-node -r tsconfig-paths/register --transpile-only src/run-migrate-up-redo.ts",
"db:dev:migrate-up": "npx ts-node -r tsconfig-paths/register --transpile-only src/run-migrate-up.ts",
"db:dev:create": "typeorm-ts-node-commonjs migration:create ./src/_migrations/manual-migration",
"db:prod:data-anonymize": "node dist/run-data-anonymization.js ",
"db:prod:migrate-down:last": "node dist/run-migrate-down-last.js",
"db:test:migrate-down:last": "ENV_FILE=tests-local npx ts-node -r tsconfig-paths/register --transpile-only src/run-migrate-down-last.ts",
"db:test:migrate-redo": "ENV_FILE=tests-local npx ts-node -r tsconfig-paths/register --transpile-only src/run-migrate-up-redo.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface UseBaseJwtPayload<T extends UserProfile = UserProfile> {
_userProfile: T;
_userId: number;
_jwtPayloadVersion: number;
isSuperAdminDomifa: boolean;
userRightStatus: UserRightStatus;
isSuperAdminDomifa?: boolean;
userRightStatus?: UserRightStatus;
territories?: string[];
}
2 changes: 1 addition & 1 deletion packages/backend/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { StructuresAuthController } from "./structures-auth.controller";
JwtModule.register({
secret: domifaConfig().security.jwtSecret,
signOptions: {
expiresIn: "12h",
expiresIn: "24h",
},
})
),
Expand Down
5 changes: 0 additions & 5 deletions packages/backend/src/config/domifaConfig.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@ export function loadConfig(x: Partial<DomifaEnv>): DomifaConfig {
),
sentryDsn,
},
anonymizer: {
password: configParser.parseString(x, "DOMIFA_ANONYMIZER_PASSWORD", {
required: false,
}),
},
},
logger: {
logHttpRequests: configParser.parseBoolean(
Expand Down
3 changes: 0 additions & 3 deletions packages/backend/src/config/model/DomifaConfig.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export type DomifaConfig = {
sentryDsn: string; // DOMIFA_SENTRY_DSN_BACKEND
debugModeEnabled: boolean; // DOMIFA_SENTRY_DEBUG_MODE_ENABLED
};
anonymizer: {
password: string; // DOMIFA_ANONYMIZER_PASSWORD
};
};
logger: {
logHttpRequests: boolean; // DOMIFA_LOG_HTTP_REQUESTS
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { subDays, subWeeks } from "date-fns";
import { subHours, subWeeks } from "date-fns";

import { domifaConfig } from "../../../../config";
import { appLogger } from "../../../../util";
Expand Down Expand Up @@ -52,9 +52,9 @@ function isAccountLockedForOperation({
eventsHistory: UserStructureSecurityEvent[];
userId: number;
}) {
const oneDayAgo = subDays(new Date(), 1);
const oneHourAgo = subHours(new Date(), 1);
const eventsRecentHistory = eventsHistory.filter(
(x) => new Date(x.date) > oneDayAgo
(x) => new Date(x.date) > oneHourAgo
);

if (eventsHistory.length) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { subDays, subWeeks } from "date-fns";
import { subHours, subWeeks } from "date-fns";

import { domifaConfig } from "../../../../config";
import { appLogger } from "../../../../util";
Expand Down Expand Up @@ -58,9 +58,9 @@ function isAccountLockedForOperation({
}
}

const oneDayAgo = subDays(new Date(), 1);
const oneHourAgo = subHours(new Date(), 1);
const eventsRecentHistory = eventsHistory.filter(
(x) => new Date(x.date) > oneDayAgo
(x) => new Date(x.date) > oneHourAgo
);

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { structureRepository } from "../../../database";

import { usagerRepository } from "../../../database/services/usager/usagerRepository.service";
import { userUsagerRepository } from "../../../database/services/user-usager/userUsagerRepository.service";
import { appLogger } from "../../../util";
import {
CURRENT_JWT_PAYLOAD_VERSION,
UserUsagerAuthenticated,
Expand All @@ -25,8 +24,6 @@ export class UsagersAuthService {
usagerUUID: user.usagerUUID,
structureId: user.structureId,
lastLogin: user.lastLogin,
isSuperAdminDomifa: false,
userRightStatus: "structure",
};
return {
access_token: this.jwtService.sign(payload),
Expand Down Expand Up @@ -57,15 +54,15 @@ export class UsagersAuthService {
public async findAuthUserUsager(
payload: Pick<UserUsagerJwtPayload, "_userId">
): Promise<UserUsagerAuthenticated> {
const user = await userUsagerRepository.findOneBy({ id: payload._userId });

const usager = await usagerRepository.findOneBy({ uuid: user.usagerUUID });
const user = await userUsagerRepository.findOneByOrFail({
id: payload._userId,
});

if (typeof user.structureId === "undefined") {
appLogger.debug("[TRACK BUG] " + JSON.stringify(user));
}
const usager = await usagerRepository.findOneByOrFail({
uuid: user.usagerUUID,
});

const structure = await structureRepository.findOneBy({
const structure = await structureRepository.findOneByOrFail({
id: user.structureId,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MailsModule } from "../mails/mails.module";
import { StatsModule } from "../stats/stats.module";
import { UsagersModule } from "../usagers/usagers.module";
import { UserDto } from "../users/dto/user.dto";
import { UsersController } from "../users/users.controller";
import { UsersController } from "../users/controllers/users.controller";
import { UsersModule } from "../users/users.module";
import { ExpressResponse } from "../util/express";
import { AppTestContext, AppTestHelper } from "../util/test";
Expand Down

0 comments on commit 13eb884

Please sign in to comment.