diff --git a/CHANGELOG.md b/CHANGELOG.md index 8411d61f5..56ea9759a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Removed suggested example queries from the Ask landing page. [#1674](https://github.com/sourcebot-dev/sourcebot/pull/1674) +- Require authentication for the streaming and blocking Ask APIs in Public SaaS deployments. [#1679](https://github.com/sourcebot-dev/sourcebot/pull/1679) ## [5.1.14] - 2026-09-17 diff --git a/packages/web/src/app/api/(server)/ee/chat/route.ts b/packages/web/src/app/api/(server)/ee/chat/route.ts index c8a34aa8f..58f85f1b8 100644 --- a/packages/web/src/app/api/(server)/ee/chat/route.ts +++ b/packages/web/src/app/api/(server)/ee/chat/route.ts @@ -15,7 +15,7 @@ import { getAskSkillAvailabilityAnalytics, getAskSkillTurnCompletedAnalytics } f import { apiHandler } from "@/lib/apiHandler"; import { ErrorCode } from "@/lib/errorCodes"; import { captureEvent } from "@/lib/posthog"; -import { notFound, requestBodySchemaValidationError, ServiceError, serviceErrorResponse } from "@/lib/serviceError"; +import { notAuthenticated, notFound, requestBodySchemaValidationError, ServiceError, serviceErrorResponse } from "@/lib/serviceError"; import { isServiceError } from "@/lib/utils"; import { withOptionalAuth } from "@/middleware/withAuth"; import * as Sentry from "@sentry/nextjs"; @@ -50,6 +50,10 @@ export const POST = apiHandler(async (req: NextRequest) => { const response = await sew(() => withOptionalAuth(async ({ org, user, prisma }) => { + if (env.EXPERIMENT_ASK_GH_ENABLED === 'true' && !user) { + return notAuthenticated(); + } + // Gate the generative path behind the `ask` entitlement. The client // also gates this, but server-side enforcement can't be bypassed. const askError = await checkAskEntitlement(); diff --git a/packages/web/src/ee/features/mcp/askCodebase.ts b/packages/web/src/ee/features/mcp/askCodebase.ts index 35337d29f..40cf3cb62 100644 --- a/packages/web/src/ee/features/mcp/askCodebase.ts +++ b/packages/web/src/ee/features/mcp/askCodebase.ts @@ -7,7 +7,7 @@ import { LanguageModelInfo, SBChatMessage, SearchScope } from "@/features/chat/t import { convertLLMOutputToPortableMarkdown, getAnswerPartFromAssistantMessage, getLanguageModelKey } from "@/features/chat/utils"; import { resolveModelCapabilities } from "@/features/chat/modelCapabilities.server"; import { ErrorCode } from "@/lib/errorCodes"; -import { ServiceError, ServiceErrorException } from "@/lib/serviceError"; +import { notAuthenticated, ServiceError, ServiceErrorException } from "@/lib/serviceError"; import { withOptionalAuth } from "@/middleware/withAuth"; import { ChatVisibility, Prisma } from "@sourcebot/db"; import { createLogger, env } from "@sourcebot/shared"; @@ -49,6 +49,10 @@ const blockStreamUntilFinish = async => sew(() => withOptionalAuth(async ({ org, user, prisma }) => { + if (env.EXPERIMENT_ASK_GH_ENABLED === 'true' && !user) { + return notAuthenticated(); + } + // Ask Sourcebot is a paid feature. askCodebase() is the single choke point // for the programmatic ask path (the MCP `ask_codebase` tool and the // /api/chat/blocking route both wrap it), so gating here covers both without