fix: enforce owner allowlist for commands
parent
a6fd76efeb
commit
385a7eba33
|
|
@ -204,6 +204,7 @@ export function resolveCommandAuthorization(params: {
|
||||||
ownerCandidatesForCommands.push(...normalizedTo);
|
ownerCandidatesForCommands.push(...normalizedTo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const ownerAllowAll = ownerAllowFromList.some((entry) => entry.trim() === "*");
|
||||||
const explicitOwners = ownerAllowFromList.filter((entry) => entry !== "*");
|
const explicitOwners = ownerAllowFromList.filter((entry) => entry !== "*");
|
||||||
const ownerList = Array.from(
|
const ownerList = Array.from(
|
||||||
new Set(explicitOwners.length > 0 ? explicitOwners : ownerCandidatesForCommands),
|
new Set(explicitOwners.length > 0 ? explicitOwners : ownerCandidatesForCommands),
|
||||||
|
|
@ -228,11 +229,15 @@ export function resolveCommandAuthorization(params: {
|
||||||
|
|
||||||
const enforceOwner = Boolean(dock?.commands?.enforceOwnerForCommands);
|
const enforceOwner = Boolean(dock?.commands?.enforceOwnerForCommands);
|
||||||
const senderIsOwner = Boolean(matchedSender);
|
const senderIsOwner = Boolean(matchedSender);
|
||||||
const isOwnerForCommands =
|
const ownerAllowlistConfigured = ownerAllowAll || explicitOwners.length > 0;
|
||||||
!enforceOwner ||
|
const requireOwner = enforceOwner || ownerAllowlistConfigured;
|
||||||
allowAll ||
|
const isOwnerForCommands = !requireOwner
|
||||||
ownerCandidatesForCommands.length === 0 ||
|
? true
|
||||||
Boolean(matchedCommandOwner);
|
: ownerAllowAll
|
||||||
|
? true
|
||||||
|
: ownerAllowlistConfigured
|
||||||
|
? senderIsOwner
|
||||||
|
: allowAll || ownerCandidatesForCommands.length === 0 || Boolean(matchedCommandOwner);
|
||||||
const isAuthorizedSender = commandAuthorized && isOwnerForCommands;
|
const isAuthorizedSender = commandAuthorized && isOwnerForCommands;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -165,7 +165,7 @@ describe("resolveCommandAuthorization", () => {
|
||||||
commandAuthorized: true,
|
commandAuthorized: true,
|
||||||
});
|
});
|
||||||
expect(otherAuth.senderIsOwner).toBe(false);
|
expect(otherAuth.senderIsOwner).toBe(false);
|
||||||
expect(otherAuth.isAuthorizedSender).toBe(true);
|
expect(otherAuth.isAuthorizedSender).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue