Skip to content

Commit e58aa31

Browse files
committed
fix: stop forwarding MongoDB TLS file paths on Cloud
MongoIntegration forwarded tlsCertificateKeyFile/tlsCAFile from the datasource config directly into the MongoDB driver as filesystem paths, regardless of environment. The builder UI only exposes these fields when SELF_HOSTED is true, but that gating was UI-only — the backend still accepted and used them on Cloud if present in the request payload, which is unsafe on a shared, multi-tenant server. buildMongoClientOptions() now only forwards these fields into the driver when environment.SELF_HOSTED is true, enforcing server-side what the UI already implied. Self-hosted behavior is unchanged.
1 parent b4227c4 commit e58aa31

2 files changed

Lines changed: 54 additions & 4 deletions

File tree

packages/server/src/integrations/mongodb.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,25 @@ const getSchema = () => {
349349

350350
const SCHEMA: Integration = getSchema()
351351

352+
export function buildMongoClientOptions(
353+
config: MongoDBConfig,
354+
selfHosted = !!environment.SELF_HOSTED
355+
): MongoClientOptions {
356+
return selfHosted
357+
? {
358+
tlsCertificateKeyFile: config.tlsCertificateKeyFile || undefined,
359+
tlsCAFile: config.tlsCAFile || undefined,
360+
}
361+
: {}
362+
}
363+
352364
export class MongoIntegration implements IntegrationBase {
353365
private config: MongoDBConfig
354366
private client: MongoClient
355367

356368
constructor(config: MongoDBConfig) {
357369
this.config = config
358-
const options: MongoClientOptions = {
359-
tlsCertificateKeyFile: config.tlsCertificateKeyFile || undefined,
360-
tlsCAFile: config.tlsCAFile || undefined,
361-
}
370+
const options = buildMongoClientOptions(config)
362371
this.client = new MongoClient(config.connectionString, options)
363372
}
364373

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { buildMongoClientOptions, MongoDBConfig } from "../mongodb"
2+
import { withEnv } from "../../environment"
3+
4+
describe("MongoDB Integration", () => {
5+
const baseConfig: MongoDBConfig = {
6+
connectionString: "mongodb://localhost:27017",
7+
db: "test",
8+
tlsCertificateKeyFile: "/etc/passwd",
9+
tlsCAFile: "/etc/shadow",
10+
}
11+
12+
describe("buildMongoClientOptions", () => {
13+
it("drops tlsCertificateKeyFile and tlsCAFile when not self-hosted", () => {
14+
const options = buildMongoClientOptions(baseConfig, false)
15+
16+
expect(options).toEqual({})
17+
})
18+
19+
it("passes tlsCertificateKeyFile and tlsCAFile through when self-hosted", () => {
20+
const options = buildMongoClientOptions(baseConfig, true)
21+
22+
expect(options).toEqual({
23+
tlsCertificateKeyFile: "/etc/passwd",
24+
tlsCAFile: "/etc/shadow",
25+
})
26+
})
27+
28+
it("defaults to environment.SELF_HOSTED when not explicitly provided", () => {
29+
withEnv({ SELF_HOSTED: undefined }, () => {
30+
expect(buildMongoClientOptions(baseConfig)).toEqual({})
31+
})
32+
33+
withEnv({ SELF_HOSTED: "true" }, () => {
34+
expect(buildMongoClientOptions(baseConfig)).toEqual({
35+
tlsCertificateKeyFile: "/etc/passwd",
36+
tlsCAFile: "/etc/shadow",
37+
})
38+
})
39+
})
40+
})
41+
})

0 commit comments

Comments
 (0)