Skip to content

Commit 28c3b67

Browse files
fix(sentry): Also deny user deletion on egress
Reject DELETE /api/0/users/{user}/, including users/me, with the same policy as organization and project deletion.
1 parent 82de897 commit 28c3b67

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* Sentry egress policy.
33
*
4-
* Junior never deletes a Sentry organization or project, whatever the
5-
* credential, grant, or Actor role. Deletion is irreversible for the people
6-
* who own the data, so a person does it in Sentry.
4+
* Junior never deletes a Sentry organization, project, or user, whatever
5+
* the credential, grant, or Actor role. Deletion is irreversible for the
6+
* people who own the data, so a person does it in Sentry.
77
*/
88
import { EgressPolicyDenied } from "@sentry/junior-plugin-api";
99
import type { EgressHookContext } from "@sentry/junior-plugin-api";
@@ -19,11 +19,10 @@ function apiPathSegments(url: URL): string[] {
1919
return pathname.split("/").filter(Boolean);
2020
}
2121

22-
// `DELETE /api/0/organizations/{org}/` and
23-
// `DELETE /api/0/projects/{org}/{project}/`.
24-
function isOrganizationOrProjectDeletion(
25-
request: EgressHookContext["request"],
26-
): boolean {
22+
// `DELETE /api/0/organizations/{org}/`,
23+
// `DELETE /api/0/projects/{org}/{project}/`, and
24+
// `DELETE /api/0/users/{user}/`.
25+
function isProtectedDeletion(request: EgressHookContext["request"]): boolean {
2726
if (request.method.toUpperCase() !== "DELETE") {
2827
return false;
2928
}
@@ -35,17 +34,18 @@ function isOrganizationOrProjectDeletion(
3534
}
3635
return (
3736
(resource === "organizations" && rest.length === 1) ||
38-
(resource === "projects" && rest.length === 2)
37+
(resource === "projects" && rest.length === 2) ||
38+
(resource === "users" && rest.length === 1)
3939
);
4040
}
4141

42-
/** Deny Sentry organization and project deletion from the Sandbox. */
42+
/** Deny Sentry organization, project, and user deletion from the Sandbox. */
4343
export function enforceSentryEgressPolicy(
4444
request: EgressHookContext["request"],
4545
): void {
46-
if (isOrganizationOrProjectDeletion(request)) {
46+
if (isProtectedDeletion(request)) {
4747
throw new EgressPolicyDenied(
48-
"Junior does not delete Sentry organizations or projects. A person must do this in Sentry. This is a Junior policy, not a Sentry permission failure; do not ask for more Sentry permissions.",
48+
"Junior does not delete Sentry organizations, projects, or users. A person must do this in Sentry. This is a Junior policy, not a Sentry permission failure; do not ask for more Sentry permissions.",
4949
);
5050
}
5151
}

‎packages/junior-sentry/tests/egress-policy.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ describe("sentry egress policy", () => {
2626
"https://de.sentry.io/api/0/projects/sentry/junior/",
2727
"https://sentry.io/api/0//projects/sentry/junior",
2828
"https://sentry.io/api/0/projects/sentry/%6Aunior/",
29+
"https://sentry.io/api/0/users/me/",
30+
"https://us.sentry.io/api/0/users/123",
2931
])("denies DELETE %s", (url) => {
3032
expect(() => grantFor("DELETE", url)).toThrow(EgressPolicyDenied);
3133
expect(() => grantFor("delete", url)).toThrow(EgressPolicyDenied);
@@ -50,5 +52,8 @@ describe("sentry egress policy", () => {
5052
"https://sentry.io/api/0/organizations/sentry/issues/",
5153
),
5254
).toBeUndefined();
55+
expect(
56+
grantFor("DELETE", "https://sentry.io/api/0/users/me/emails/"),
57+
).toBeUndefined();
5358
});
5459
});

0 commit comments

Comments
 (0)