Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { db } from '@kilocode/web-shared/lib/drizzle';
import { kilocode_users } from '@kilocode/db';
import { and, inArray, isNull, or, sql, type SQL } from 'drizzle-orm';
import { getBlacklistedDomains } from '@kilocode/web-shared/lib/blacklist-domains-config';
import { revokeGatewayGrantsForBlockedUsers } from '@/lib/mcp-gateway/blocking-service';

/**
* Builds a WHERE condition that matches users whose `email_domain` is on the
Expand Down Expand Up @@ -115,9 +114,6 @@ export async function backfillBlockBlacklistedDomainsBatch(params: {
.returning({ id: kilocode_users.id });

totalProcessed += updated.length;
if (updated.length > 0) {
await revokeGatewayGrantsForBlockedUsers(updated.map(user => user.id));
}

if (rows.length < BATCH_SIZE) {
reachedEnd = true;
Expand Down
5 changes: 0 additions & 5 deletions apps/web/src/lib/abuse/bulkBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { db } from '@kilocode/web-shared/lib/drizzle';
import { kilocode_users } from '@kilocode/db/schema';
import { and, eq, inArray, isNull, or, sql } from 'drizzle-orm';
import { successResult, type CustomResult } from '@kilocode/web-shared/lib/maybe-result';
import { revokeGatewayGrantsForBlockedUsers } from '@/lib/mcp-gateway/blocking-service';

export type BulkBlockResponse = CustomResult<
{ updatedCount: number },
Expand Down Expand Up @@ -68,10 +67,6 @@ export async function bulkBlockUsers(
.where(and(inArray(kilocode_users.id, valid), isNull(kilocode_users.blocked_reason)))
.returning({ id: kilocode_users.id });

if (updated.length > 0) {
await revokeGatewayGrantsForBlockedUsers(updated.map(u => u.id));
}

// A short update count means some of the selected users were concurrently
// blocked between the read and the guarded update. Surface that as a
// retryable conflict so the caller can re-run and confirm their final state.
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/lib/admin/admin-action-audit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ describe('recordElevatedOrganizationAdminAction', () => {
organizationId,
requiredRoles: ['owner'],
membershipScope: scope,
action: 'organization.mcp_gateway.update',
message: 'MCP gateway: delete',
action: 'organization.gitlab_webhook_secret.rotate',
message: 'GitLab webhook secret: rotate',
}
);
}
Expand Down
3 changes: 0 additions & 3 deletions apps/web/src/lib/kilo-pass/cancel-and-refund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { closePauseEvent } from '@kilocode/web-shared/lib/kilo-pass/pause-events
import { releaseScheduledChangeForSubscription } from '@/lib/kilo-pass/scheduled-change-release';
import { fromMicrodollars } from '@kilocode/app-shared/utils';
import { KiloPassPaymentProvider } from '@kilocode/web-shared/lib/kilo-pass/enums';
import { revokeGatewayGrantsForBlockedUser } from '@/lib/mcp-gateway/blocking-service';
import { blockUser } from '@/lib/user/block';

type Db = typeof defaultDb;
Expand Down Expand Up @@ -269,8 +268,6 @@ export async function cancelAndRefundKiloPassForUser({
return balanceReset;
});

await revokeGatewayGrantsForBlockedUser(userId);

return {
status: refundLatestPayment ? 'cancelled_and_refunded' : 'cancelled',
refundedAmountCents,
Expand Down
2 changes: 0 additions & 2 deletions apps/web/src/lib/kilo-pass/stripe-handlers-invoice-paid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import {
import { processTopUp } from '@kilocode/web-shared/lib/credits';
import { randomUUID } from 'node:crypto';
import { releaseScheduledChangeForSubscription } from '@/lib/kilo-pass/scheduled-change-release';
import { revokeGatewayGrantsForBlockedUser } from '@/lib/mcp-gateway/blocking-service';
import {
computeMonthlyKiloPassStreak,
updateKiloPassThresholdAfterBaseCredits,
Expand Down Expand Up @@ -1002,7 +1001,6 @@ export async function handleKiloPassInvoicePaid(params: {
}

if (duplicateCardEnforcement) {
await revokeGatewayGrantsForBlockedUser(duplicateCardEnforcement.kiloUserId);
await enforceDuplicateCardBlock({
enforcement: duplicateCardEnforcement,
eventId,
Expand Down
83 changes: 0 additions & 83 deletions apps/web/src/lib/mcp-gateway/blocking-service.ts

This file was deleted.

92 changes: 0 additions & 92 deletions apps/web/src/lib/mcp-gateway/lifecycle-service.ts

This file was deleted.

2 changes: 0 additions & 2 deletions apps/web/src/lib/stripe/disputes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import { KiloClawInternalClient } from '@/lib/kiloclaw/kiloclaw-internal-client'
import { client } from '@kilocode/web-shared/lib/stripe-client';
import { fromMicrodollars } from '@kilocode/app-shared/utils';
import { revokeWebSessions } from '@kilocode/web-shared/lib/web-session-revocation';
import { revokeGatewayGrantsForBlockedUser } from '@/lib/mcp-gateway/blocking-service';
import { blockUser } from '@/lib/user/block';

type StripeReference = string | { id: string } | null | undefined;
Expand Down Expand Up @@ -533,7 +532,6 @@ async function blockUserForAcceptedDispute(params: {
});

await revokeWebSessions(userId);
await revokeGatewayGrantsForBlockedUser(userId);

return {
status: StripeDisputeActionStatus.Completed,
Expand Down
6 changes: 1 addition & 5 deletions apps/web/src/lib/stytch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { updateStytchValidation } from '@kilocode/web-shared/lib/customerInfo';
import { domainIsRestrictedFromStytchFreeCredits } from './domainIsRestrictedFromStytchFreeCredits';
import { grantCreditForCategory } from '@kilocode/web-shared/lib/promotionalCredits';
import PostHogClient from '@kilocode/web-shared/lib/posthog';
import { revokeGatewayGrantsForBlockedUser } from '@/lib/mcp-gateway/blocking-service';

const NEXT_PUBLIC_STYTCH_PROJECT_ENV = getEnvVariable('NEXT_PUBLIC_STYTCH_PROJECT_ENV');
const STYTCH_PROJECT_ID = getEnvVariable('STYTCH_PROJECT_ID');
Expand Down Expand Up @@ -151,13 +150,10 @@ export async function saveFingerprints(

// Autoban users blocked by Stytch for smart rate limit abuse
if (verdict.action === 'BLOCK' && verdict.reasons.includes('SMART_RATE_LIMIT_BANNED')) {
const didBlock = await blockUser({
await blockUser({
kiloUserId: user.id,
reason: 'autoban: stytch SMART_RATE_LIMIT_BANNED',
});
if (didBlock) {
await revokeGatewayGrantsForBlockedUser(user.id);
}
if (process.env.NODE_ENV !== 'test')
console.log('SECURITY: autobanned user for SMART_RATE_LIMIT_BANNED:', {
userId: user.id,
Expand Down
Loading