-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat cerfa dates #3600
Merged
Merged
Feat cerfa dates #3600
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/backend/src/auth/decorators/current-structure.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createParamDecorator, ExecutionContext } from "@nestjs/common"; | ||
import { Structure } from "@domifa/common"; | ||
|
||
export const CurrentStructure = createParamDecorator( | ||
(_data: unknown, ctx: ExecutionContext) => { | ||
const request = ctx.switchToHttp().getRequest(); | ||
return request.structure as Structure; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/backend/src/auth/guards/structure-access.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
CanActivate, | ||
ExecutionContext, | ||
HttpException, | ||
HttpStatus, | ||
Injectable, | ||
} from "@nestjs/common"; | ||
|
||
import { appLogger } from "../../util"; | ||
import { structureRepository } from "../../database"; | ||
|
||
@Injectable() | ||
export class StructureAccessGuard implements CanActivate { | ||
public async canActivate(context: ExecutionContext) { | ||
const r = context.switchToHttp().getRequest(); | ||
|
||
console.log(r?.params?.structureId); | ||
console.log(r?.user?.isSuperAdminDomifa); | ||
if (!r?.params?.structureId || !r?.user?.isSuperAdminDomifa) { | ||
appLogger.error("[StructureAccessGuard] invalid structureId for admin", { | ||
sentry: true, | ||
context: { | ||
usagerRef: r?.params?.uui, | ||
structureId: r?.user?.structureId, | ||
user: r?.user?._id, | ||
}, | ||
}); | ||
throw new HttpException( | ||
"STRUCTURE_INFORMATION_NOT_FOUND", | ||
HttpStatus.BAD_REQUEST | ||
); | ||
} | ||
|
||
const structureId = parseInt(r.params.structureId, 10); | ||
|
||
try { | ||
const structure = await structureRepository.findOneOrFail({ | ||
where: { | ||
id: structureId, | ||
}, | ||
}); | ||
r.structure = structure; | ||
return r; | ||
} catch (e) { | ||
appLogger.error("[UsagerAccessGuard] Structure not found", { | ||
sentry: true, | ||
context: { | ||
structureId, | ||
user: r?.user?._id, | ||
role: r?.user?.role, | ||
}, | ||
}); | ||
throw new HttpException("USAGER_NOT_FOUND", HttpStatus.BAD_REQUEST); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Log injection Medium
Copilot Autofix AI 28 days ago
To fix the problem, we need to sanitize the user input before logging it. Specifically, we should remove any newline characters from the
structureId
parameter to prevent log injection attacks. This can be done using theString.prototype.replace
method to strip out newline characters.We will modify the code to sanitize
r?.params?.structureId
before logging it. This involves creating a sanitized version ofstructureId
and then logging the sanitized value.