Skip to content

Commit 81aa003

Browse files
icecrasher321claude
andcommitted
fix(logfire): reject an explicit region outside the known set
An out-of-set region reaching getLogfireBaseUrl (from persisted workflow state, which the LogfireRegion type does not guarantee at runtime) indexed REGION_BASE_URLS with no membership check and produced "undefined/v2/query", which the executor would resolve against the app origin. Throw the same clear error already used for an unrecognized token prefix. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d70ac01 commit 81aa003

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

apps/sim/tools/logfire/utils.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* @vitest-environment node
33
*/
44
import { describe, expect, it } from 'vitest'
5+
import type { LogfireRegion } from '@/tools/logfire/types'
56
import {
67
buildLogfireQueryBody,
78
extractLogfireColumns,
@@ -40,6 +41,12 @@ describe('getLogfireBaseUrl', () => {
4041
)
4142
})
4243

44+
it('rejects an explicit region outside the known set rather than building undefined/', () => {
45+
expect(() => getLogfireBaseUrl('pylf_v1_us_abc', 'apac' as unknown as LogfireRegion)).toThrow(
46+
"Unrecognized Logfire region 'apac'"
47+
)
48+
})
49+
4350
it('lets a self-hosted host override both the region and the token prefix', () => {
4451
expect(getLogfireBaseUrl('pylf_v1_eu_abc', 'us', 'https://logfire.example.com')).toBe(
4552
'https://logfire.example.com'

apps/sim/tools/logfire/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,15 @@ function normalizeHost(host?: string): string | undefined {
102102
export function getLogfireBaseUrl(apiKey: string, region?: LogfireRegion, host?: string): string {
103103
const selfHosted = normalizeHost(host)
104104
if (selfHosted) return selfHosted
105-
if (region && region !== 'auto') return REGION_BASE_URLS[region]
105+
106+
if (region && region !== 'auto') {
107+
if (!isCloudRegion(region)) {
108+
throw new Error(
109+
`Unrecognized Logfire region '${region}'. Set Region to us or eu, or set Host explicitly.`
110+
)
111+
}
112+
return REGION_BASE_URLS[region]
113+
}
106114

107115
const detected = TOKEN_REGION_PATTERN.exec(apiKey?.trim() ?? '')?.[1]
108116
if (!detected) return REGION_BASE_URLS.us

0 commit comments

Comments
 (0)