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

Commit

Permalink
fix(signature): ensure signature to update belongs to current user only
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Sep 11, 2022
1 parent 1ff773b commit 3a156c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
20 changes: 9 additions & 11 deletions routes/api/user(id)/relationships/signature/update.patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
UPDATE_ANYONE_ON_OWN_DEPARTMENT,
UPDATE_ANYONE_ON_ALL_DEPARTMENTS
} from "$/permissions/user_combinations"
import Merger from "!/middlewares/miscellaneous/merger"
import IDParameterValidation from "!/validations/id_parameter"
import PermissionBasedPolicy from "!/policies/permission-based"
import { user as permissionGroup } from "$/permissions/permission_list"
Expand All @@ -30,11 +31,14 @@ export default class extends MultipartController {
get filePath(): string { return __filename }

get policy(): Policy {
return new PermissionBasedPolicy(permissionGroup, [
UPDATE_OWN_DATA,
UPDATE_ANYONE_ON_OWN_DEPARTMENT,
UPDATE_ANYONE_ON_ALL_DEPARTMENTS
])
return new Merger([
new PermissionBasedPolicy(permissionGroup, [
UPDATE_OWN_DATA,
UPDATE_ANYONE_ON_OWN_DEPARTMENT,
UPDATE_ANYONE_ON_ALL_DEPARTMENTS
]),
new BelongsToCurrentUserPolicy(UserManager)
]) as unknown as Policy
}

get validations(): Validation[] {
Expand Down Expand Up @@ -66,12 +70,6 @@ export default class extends MultipartController {
})
}

get postParseMiddlewares(): Policy[] {
return [
new BelongsToCurrentUserPolicy()
]
}

async handle(request: AuthenticatedIDRequest, unusedResponse: Response)
: Promise<OkResponseInfo> {
const manager = new SignatureManager(request.transaction, request.cache)
Expand Down
6 changes: 3 additions & 3 deletions server/bases/controller-likes/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export default abstract class extends ControllerLike {

async intermediate(request: Request, response: Response, next: NextFunction): Promise<void> {
return await this.handle(request, response)
.then(responseInfo => this.respond(response, responseInfo))
.then(() => next())
.catch(next)
.then(responseInfo => this.respond(response, responseInfo))
.then(() => next())
.catch(next)
}

private respond(response: Response, responseInfo: ResponseInfo|void): void {
Expand Down

0 comments on commit 3a156c8

Please sign in to comment.