-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treat
null
and undefined
scope dimensions the same in `AccessCont…
…rolService#isAllowed` (#2643) Optional scope dimensions may sometimes be `null` or `undefined` depending on how the scope object is created. For instance, when the scope is loaded from the database, the optional dimension will be `null`, but when the scope is coming from GraphQL, the dimension can be `undefined`. Due to strict equality comparison, this led to incorrect access control checks in `AccessControlService#isAllowed`. This is now prevented by treating `null` and `undefined` dimensions as the same when checking the scope.
- Loading branch information
1 parent
9e2b0fa
commit 72cf8fd
Showing
3 changed files
with
57 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@comet/cms-api": patch | ||
--- | ||
|
||
Treat `null` and `undefined` scope dimensions the same in `AccessControlService#isAllowed` | ||
|
||
Optional scope dimensions may sometimes be `null` or `undefined` depending on how the scope object is created. | ||
For instance, when the scope is loaded from the database, the optional dimension will be `null`, but when the scope is coming from GraphQL, the dimension can be `undefined`. | ||
Due to strict equality comparison, this led to incorrect access control checks in `AccessControlService#isAllowed`. | ||
This is now prevented by treating `null` and `undefined` dimensions as the same when checking the scope. |
35 changes: 35 additions & 0 deletions
35
packages/api/cms-api/src/user-permissions/access-control.service.test.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,35 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
|
||
import { AbstractAccessControlService } from "./access-control.service"; | ||
import { CurrentUser } from "./dto/current-user"; | ||
|
||
describe("AbstractAccessControlService", () => { | ||
class ConcreteAccessControlService extends AbstractAccessControlService {} | ||
|
||
let service: ConcreteAccessControlService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ConcreteAccessControlService], | ||
}).compile(); | ||
|
||
service = module.get<ConcreteAccessControlService>(ConcreteAccessControlService); | ||
}); | ||
|
||
describe("isAllowed", () => { | ||
it("should treat null and undefined scope dimensions the same", () => { | ||
const user: CurrentUser = { | ||
id: "b26d86a7-32bb-4c84-ab9d-d167dddd40ff", | ||
name: "User", | ||
email: "user@example.com", | ||
permissions: [{ permission: "pageTree", contentScopes: [{ domain: "main", language: null }] }], | ||
}; | ||
|
||
expect(service.isAllowed(user, "pageTree", { domain: "main" })).toBe(true); | ||
|
||
expect(service.isAllowed(user, "pageTree", { domain: "main", language: null })).toBe(true); | ||
|
||
expect(service.isAllowed(user, "pageTree", { domain: "main", language: undefined })).toBe(true); | ||
}); | ||
}); | ||
}); |
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