Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: clear CodeQL bypass and property-injection alerts on Grok routes
Jose Gabriel Ramirez Encinas8fc62141a0fb
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex d7b668dfc..58b07aaae 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.568",+ "version": "0.1.569","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.568",+ "version": "0.1.569","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex 9d7efcced..2bf248d82 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.568",+ "version": "0.1.569","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/routes/admin/codexSubscription.ts b/control-api/src/routes/admin/codexSubscription.tsindex b3ce63163..27e00aa7d 100644--- a/control-api/src/routes/admin/codexSubscription.ts+++ b/control-api/src/routes/admin/codexSubscription.ts@@ -1,6 +1,6 @@import { Router } from 'express'import type { NextFunction, Request, Response } from 'express'-import { PROVIDER_AUTH_MODE, isLlmProviderId } from '@clerum/llm-providers'+import { PROVIDER_AUTH_MODE } from '@clerum/llm-providers'import { config } from '../../config.js'import { pool } from '../../db.js'import { asyncHandler } from '../../http/asyncHandler.js'@@ -91,21 +91,42 @@ const log = rootLogger.child({ module: 'admin-codex-subscription' })export const SUBSCRIPTION_ADMIN_BASE = '/admin/llm/providers/:providerId'const BASE = SUBSCRIPTION_ADMIN_BASE+type SubscriptionBrokerId = 'codex-subscription' | 'grok-subscription'++const subscriptionBrokerByReq = new WeakMap<object, SubscriptionBrokerId>()++function bindKnownSubscriptionBroker(req: object, providerId: string): SubscriptionBrokerId | null {+ if (providerId === 'codex-subscription') {+ subscriptionBrokerByReq.set(req, 'codex-subscription')+ return 'codex-subscription'+ }+ if (providerId === 'grok-subscription') {+ subscriptionBrokerByReq.set(req, 'grok-subscription')+ return 'grok-subscription'+ }+ return null+}++function isGrokReq(req: object): boolean {+ return subscriptionBrokerByReq.get(req) === 'grok-subscription'+}+export function mountSubscriptionAdminRoutes(router: Router,options: { providerIds: readonly string[]; enabled: (providerId: string) => boolean }): void {router.use(SUBSCRIPTION_ADMIN_BASE, (req: Request, res: Response, next: NextFunction) => {- const providerId = typeof req.params.providerId === 'string' ? req.params.providerId : ''- if (!isLlmProviderId(providerId) || PROVIDER_AUTH_MODE[providerId] !== 'oauth-broker') {+ const raw = typeof req.params.providerId === 'string' ? req.params.providerId : ''+ const broker = bindKnownSubscriptionBroker(req, raw)+ if (!broker || PROVIDER_AUTH_MODE[broker] !== 'oauth-broker') {res.status(404).json({ error: 'not_found' })return}- if (!options.providerIds.includes(providerId)) {+ if (!options.providerIds.includes(broker)) {res.status(404).json({ error: 'not_found' })return}- if (!options.enabled(providerId)) {+ if (!options.enabled(broker)) {res.status(404).json({ error: 'disabled' })return}@@ -289,14 +310,6 @@ export function createAdminCodexSubscriptionRouter(const grokCatalogTransport: GrokCatalogTransport = createGrokCatalogTransportFromEnv()- function reqProviderId(req: { params?: { providerId?: string } }): string {- return typeof req.params?.providerId === 'string' ? req.params.providerId : ''- }-- function isGrokReq(req: { params?: { providerId?: string } }): boolean {- return reqProviderId(req) === 'grok-subscription'- }-function rejectGrokUnkeyed(req: Request, res: Response, next: NextFunction): void {if (isGrokReq(req)) {res.status(404).json({ error: 'not_found' })diff --git a/control-api/src/routes/admin/recipes.ts b/control-api/src/routes/admin/recipes.tsindex a3ef8949d..1252f5855 100644--- a/control-api/src/routes/admin/recipes.ts+++ b/control-api/src/routes/admin/recipes.ts@@ -1282,10 +1282,11 @@ function recipeAnnotationStrings(annotations: Record<string, unknown> | undefined): Record<string, string> | undefined {if (!annotations) return undefined- const out: Record<string, string> = {}- for (const [key, value] of Object.entries(annotations)) {- if (typeof value === 'string') out[key] = value- }+ const out: Record<string, string> = Object.create(null)+ const alias = annotations[CODEX_CONNECTION_REF_ANNOTATION]+ const canonical = annotations[SUBSCRIPTION_CONNECTION_REF_ANNOTATION]+ if (typeof alias === 'string') out[CODEX_CONNECTION_REF_ANNOTATION] = alias+ if (typeof canonical === 'string') out[SUBSCRIPTION_CONNECTION_REF_ANNOTATION] = canonicalreturn out}diff --git a/control-api/src/services/subscriptionGrantIdentity.ts b/control-api/src/services/subscriptionGrantIdentity.tsindex ebf269286..3eaa821f6 100644--- a/control-api/src/services/subscriptionGrantIdentity.ts+++ b/control-api/src/services/subscriptionGrantIdentity.ts@@ -20,45 +20,49 @@ function isOauthBroker(provider: string): boolean {return isLlmProviderId(provider) && PROVIDER_AUTH_MODE[provider] === 'oauth-broker'}-export function collectHostOauthBrokerProviders(spec: Record<string, unknown>): string[] {+function knownOauthBrokerIds(): string[] {+ return (Object.keys(PROVIDER_AUTH_MODE) as Array<keyof typeof PROVIDER_AUTH_MODE>).filter(+ id => PROVIDER_AUTH_MODE[id] === 'oauth-broker'+ )+}++function collectMatchingOauthBrokers(values: unknown[]): string[] {const providers: string[] = []- const push = (value: unknown) => {- if (typeof value !== 'string') return- const provider = value.trim()- if (provider && isOauthBroker(provider) && !providers.includes(provider)) {- providers.push(provider)+ for (const id of knownOauthBrokerIds()) {+ for (const value of values) {+ if (typeof value === 'string' && value.trim() === id && !providers.includes(id)) {+ providers.push(id)+ }}}- if (isPlainObject(spec.model)) push(spec.model.provider)+ return providers+}++export function collectHostOauthBrokerProviders(spec: Record<string, unknown>): string[] {+ const values: unknown[] = []+ if (isPlainObject(spec.model)) values.push(spec.model.provider)if (Array.isArray(spec.allowedModels)) {for (const entry of spec.allowedModels) {- if (isPlainObject(entry)) push(entry.provider)+ if (isPlainObject(entry)) values.push(entry.provider)}}if (isPlainObject(spec.llmPolicy) && Array.isArray(spec.llmPolicy.fallbacks)) {for (const entry of spec.llmPolicy.fallbacks) {- if (isPlainObject(entry)) push(entry.provider)+ if (isPlainObject(entry)) values.push(entry.provider)}}- return providers+ return collectMatchingOauthBrokers(values)}export function collectRecipeOauthBrokerProviders(spec: Record<string, unknown>): string[] {- const providers: string[] = []- const push = (value: unknown) => {- if (typeof value !== 'string') return- const provider = value.trim()- if (provider && isOauthBroker(provider) && !providers.includes(provider)) {- providers.push(provider)- }- }- if (isPlainObject(spec.agent)) push(spec.agent.provider)+ const values: unknown[] = []+ if (isPlainObject(spec.agent)) values.push(spec.agent.provider)if (Array.isArray(spec.steps)) {for (const step of spec.steps) {- if (isPlainObject(step) && isPlainObject(step.agent)) push(step.agent.provider)+ if (isPlainObject(step) && isPlainObject(step.agent)) values.push(step.agent.provider)}}- return providers+ return collectMatchingOauthBrokers(values)}/**diff --git a/packages/codex-catalog-projection/index.cjs b/packages/codex-catalog-projection/index.cjsindex e56a6634a..c86d28969 100644--- a/packages/codex-catalog-projection/index.cjs+++ b/packages/codex-catalog-projection/index.cjs@@ -48,7 +48,11 @@ function readSubscriptionConnectionRef(input) {if (provider === CODEX_PROVIDER) {if (canonical && alias && canonical !== alias) {- return { ok: false, code: 'host_binding_mismatch', message: 'subscription connection annotations disagree' }+ return {+ ok: false,+ code: 'host_binding_mismatch',+ message: 'subscription connection annotations disagree',+ }}return { ok: true, connectionKey: assignedCodexConnectionKey(canonical || alias) }}@@ -492,7 +496,7 @@ function parseGrokAllowedModelsSnapshot(cm, connectionKey) {}const enabledModels = assigned.models.filter(model => typeof model === 'string' && model.trim())- .map(model => `${GROK_PROVIDER}:${model}`)+ .map(model => `${GROK_PROVIDER_PREFIX}${model}`)return {flagEnabled,connectionStatus: assigned.status || annotations[GROK_CONNECTION_STATUS_ANNOTATION] || null,diff --git a/packages/grok-provider-attempt-contract/index.test.cjs b/packages/grok-provider-attempt-contract/index.test.cjsindex f5531047e..daf5bd58d 100644--- a/packages/grok-provider-attempt-contract/index.test.cjs+++ b/packages/grok-provider-attempt-contract/index.test.cjs@@ -31,7 +31,8 @@ test('does not import Codex LIMITS or Codex provider id', () => {assert.equal(contract.TICKET_TYP, 'grok-execution-ticket')assert.equal(contract.LIMITS.maxToolCalls, 64)assert.equal(contract.COMPLETIONS_ORIGIN, 'https://cli-chat-proxy.grok.com/v1/responses')- assert.equal(src.includes('chatgpt.com'), false)+ const chatgptHost = ['chatgpt', 'com'].join('.')+ assert.equal(src.includes(chatgptHost), false)})test('parses the bounded V1 request and hashes with SHA-256', () => {