Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

refactor(cdp): render liquid templates from in-memory partials (#66917)

Tom Piccirelloe016a75a64af
diff --git a/nodejs/src/cdp/utils/liquid.test.ts b/nodejs/src/cdp/utils/liquid.test.ts
index 595a65f697c4..5826cd4351aa 100644
--- a/nodejs/src/cdp/utils/liquid.test.ts
+++ b/nodejs/src/cdp/utils/liquid.test.ts
@@ -1,3 +1,6 @@
+import * as fs from 'fs'
+import * as path from 'path'
+
import { HogFunctionInvocationGlobalsWithInputs } from '../types'
import { LiquidRenderer } from './liquid'
@@ -219,6 +222,34 @@ describe('LiquidRenderer', () => {
})
})
+ describe.each(['render', 'include', 'layout'])('file inclusion via the %s tag is disabled', (tag) => {
+ it('does not disclose local files within the working directory', () => {
+ // The partial must live under the worker's cwd: LiquidJS confines file lookups there.
+ const fixtureName = `liquid-fs-fixture-${process.pid}.txt`
+ const fixturePath = path.join(process.cwd(), fixtureName)
+ const secret = 'TOP_SECRET_FILE_CONTENTS'
+ fs.writeFileSync(fixturePath, secret)
+
+ try {
+ LiquidRenderer['_liquid'] = null
+ const template = `{% ${tag} '${fixtureName}' %}`
+
+ let result: string
+ try {
+ result = LiquidRenderer.renderWithHogFunctionGlobals(template, globals)
+ } catch {
+ // A thrown lookup error also means the file was not disclosed
+ result = ''
+ }
+
+ expect(result).not.toContain(secret)
+ } finally {
+ fs.unlinkSync(fixturePath)
+ LiquidRenderer['_liquid'] = null
+ }
+ })
+ })
+
describe('renderWithHogFunctionGlobals', () => {
it('renders with hog function globals', () => {
const template = 'Event: {{ event.event }}, Person: {{ person.name }}'
diff --git a/nodejs/src/cdp/utils/liquid.ts b/nodejs/src/cdp/utils/liquid.ts
index 01a7851c46bf..48b799a2fdfd 100644
--- a/nodejs/src/cdp/utils/liquid.ts
+++ b/nodejs/src/cdp/utils/liquid.ts
@@ -11,6 +11,9 @@ export class LiquidRenderer {
if (!this._liquid) {
this._liquid = new Liquid({
outputEscape: 'escape',
+ // Render partials from an in-memory map only: this disables LiquidJS's filesystem-backed
+ // partial loading, so user-controlled templates can't read local files via include/render/layout.
+ templates: {},
})
}
return this._liquid