Skip to content

Commit 739a339

Browse files
committed
fix: fix bug where invalid scope would result in full permission revoke
1 parent 96faa58 commit 739a339

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/multichain-api-middleware/src/handlers/wallet-revokeSession.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
JsonRpcEngineEndCallback,
1010
} from '@metamask/json-rpc-engine';
1111
import {
12+
CaveatMutatorOperation,
1213
PermissionDoesNotExistError,
1314
UnrecognizedSubjectError,
1415
} from '@metamask/permission-controller';
@@ -37,10 +38,17 @@ function partialRevokePermissions(
3738
).value;
3839

3940
for (const scopeString of scopes) {
40-
updatedCaveatValue = Caip25CaveatMutators[Caip25CaveatType].removeScope(
41+
const result = Caip25CaveatMutators[Caip25CaveatType].removeScope(
4142
updatedCaveatValue,
4243
scopeString,
43-
)?.value ?? {
44+
);
45+
46+
// If operation is a Noop, it means a scope was passed that was not present in the permission, so we proceed with the loop
47+
if (result.operation === CaveatMutatorOperation.Noop) {
48+
continue;
49+
}
50+
51+
updatedCaveatValue = result?.value ?? {
4452
requiredScopes: {},
4553
optionalScopes: {},
4654
sessionProperties: {},

0 commit comments

Comments
 (0)