Skip to content

fix(account): hasWorkspacePermission returned true for missing grants - #11067

Merged
ArtyomSavchenko merged 1 commit into
hcengineering:developfrom
MichaelUray:fix/workspace-permission-null-check
Oct 14, 2026
Merged

ArtyomSavchenko merged 1 commit into
hcengineering:developfrom
MichaelUray:fix/workspace-permission-null-check

Conversation

@MichaelUray

Copy link
Copy Markdown
Contributor

Summary

AccountDB.hasWorkspacePermission reports every permission as granted.

Both implementations do

const result = await this.workspacePermission.findOne({ workspaceUuid, accountUuid, permission })
return result !== undefined

but findOne resolves to null when nothing matches (PostgresDbCollection.findOne returns … ?? null, the Mongo driver returns null), so the comparison is always true.

This PR compares against null instead (result != null) in the Postgres and the Mongo implementation and adds tests for the missing and the existing grant in both.

Impact

No upstream code path consumes hasWorkspacePermission today (the import permission UI uses getWorkspacePermissions), so nothing is exposed right now — but any server-side check built on this method (for example a per-workspace "may create projects" grant) would silently allow everyone.

Testing

  • npx jest src/__tests__/postgres.test.ts src/__tests__/mongo.test.ts in server/account — new tests fail before the change, pass after.
  • Verified on a self-hosted deployment where a permission check is built on this method: before the fix an account without the grant was allowed, after the fix it is denied, and granting/revoking works as expected.

findOne resolves to null when nothing matches, but both the Postgres and
the Mongo implementation compared the result against undefined, so every
lookup reported the permission as granted. Compare against null instead.

Signed-off-by: Michael Uray <michaeluray@users.noreply.github.com>
@ArtyomSavchenko
ArtyomSavchenko merged commit 698b287 into hcengineering:develop Oct 14, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants