Skip to content

feat: add Go framework support - #945

Merged
sarahxsanders merged 6 commits into
mainfrom
posthog-code/go-framework-support
Aug 21, 2026
Merged

sarahxsanders merged 6 commits into
mainfrom
posthog-code/go-framework-support

Conversation

@sarahxsanders

@sarahxsanders sarahxsanders commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

Related PRs:

Adds Go as a supported framework, following the backend-framework pattern (Rails):

  • Integration.go enum entry at the end of the frameworks block, before the language fallbacks — a Go repo with an embedded frontend package.json still resolves to Go (covered by a new detection test)
  • GO_AGENT_CONFIG in src/frameworks/go/ — claims a go.mod with a module directive (a bare directory of .go files falls through); gathers the go 1.x directive as agent context; installs via go get github.com/posthog/posthog-go
  • goModulesPackageManager helper + FRAMEWORK_REGISTRY entry
  • bash-fence grammar for go: allows get|build|vet|fmt|version|list and go mod tidy/download/verify/graph/why; go run/test/generate stay denied (arbitrary code execution) and go mod edit stays denied (can rewrite module requirements to arbitrary sources)
  • Pins framework: go on integration-go in the variant-resolution contract test, matching the context-mill PR above

Why: the wizard docs page lists Go as "Coming soon"; instead of removing the label (posthog.com#18797), we're making the wizard actually support it.

Verification: pnpm build ✅, pnpm test ✅ (1536 tests, incl. new go detect + fence tests), pnpm fix ✅


Created with PostHog Code

@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci basic-integration
  • /wizard-ci mcp-analytics
  • /wizard-ci revenue

Test an individual app:

  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
Show more apps
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci revenue/stripe

Results will be posted here when complete.

Adds Go as a supported framework following the backend-framework pattern (Rails):

- Integration.go enum entry at the end of the frameworks block, before the language fallbacks
- GO_AGENT_CONFIG in src/frameworks/go/ — claims a go.mod with a module directive, gathers the go directive version as agent context, installs via go get github.com/posthog/posthog-go
- goModulesPackageManager helper + FRAMEWORK_REGISTRY entry
- bash-fence grammar for the go binary: get/build/vet/fmt/version/list plus go mod tidy/download/verify/graph/why; run/test/generate stay denied (arbitrary code execution), go mod edit stays denied (rewrites module requirements)
- Pins framework: go on integration-go in the variant-resolution contract test, matching context-mill PR #267 which must release before this merges
- Marks go.mod as a real framework target in the agentic manifest comment

Generated-By: PostHog Code
Task-Id: 9c949855-7611-48f2-b8b5-7aa4112543e5
go build/vet were allowed by subcommand without inspecting flags, so
`go build -toolexec=/tmp/x.sh` would run an arbitrary program on every
build. Deny the -toolexec flag explicitly (both = and space forms) and
add attack-corpus tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sarahxsanders
sarahxsanders marked this pull request as ready for review July 24, 2026 15:16
@sarahxsanders
sarahxsanders requested a review from a team as a code owner July 24, 2026 15:16
Additive conflicts against the Flutter work: both language helpers kept in
bash-fence, package-manager, and their tests.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
// allowed verbs above are not safe with it. Deny it explicitly.
const toolexec = parts
.slice(2)
.find((p) => p === '-toolexec' || p.startsWith('-toolexec='));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical: Arbitrary program execution through Go tool flags

A malicious repository can include an executable payload and prompt the agent to run go vet -vettool=./payload ./...; this passes the fence and causes Go to execute the payload. The current check also misses --toolexec, so block both spellings of both execution flags.

Suggested change
.find((p) => p === '-toolexec' || p.startsWith('-toolexec='));
.find((p) => /^--?(?:toolexec|vettool)(?:=|$)/.test(p));

@veria-ai

veria-ai Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

PR overview

This pull request adds Go framework support, including updates to the Bash command fence for Go build and analysis commands.

Two security issues remain open, and none have yet been addressed. A malicious repository can use permitted Go tool flags to execute an arbitrary program, while unrestricted build output paths can place executable Git hooks that run later. The direct program-execution path makes the current security posture high risk.

Open issues (2)

Fixed/addressed: 0 · PR risk: 8/10

@gewenyu99

Copy link
Copy Markdown
Collaborator

Full e2e run of this PR pair (wizard #945 + context-mill #267, both with main merged in) against gotify/server — real Go server, go.mod at root.

Outcome: PostHog set up — dashboard and notebook created through prod MCP, go build ./... and go vet ./... clean on the output, defer posthogClient.Close() wired, identity via DistinctId on captures. The one conflict the outro reports is gotify's pre-existing ui/build/* gap, not this integration.

Note: the branch as filed fails at the dashboard step — its agent prompts predate the posthog_exec tool grant on main. Works once main is merged in, which for context-mill is blocked on unsigned commits.

All 25 TUI frames 01-intro.png 02-auth.png 03-run.png 04-run.png 05-run.png 06-run.png 07-run.png 08-run.png 09-run.png 10-run.png 11-run.png 12-run.png 13-run.png 14-run.png 15-run.png 16-run.png 17-run.png 18-run.png 19-run.png 20-run.png 21-outro.png 22-outro.png 23-mcp.png 24-slack-connect.png 25-keep-skills.png

gewenyu99 and others added 2 commits August 20, 2026 18:49
The result JSON parsed package.json and pubspec.yaml only, so Go, Rust, Java,
and Elixir runs reported hasPosthogDep false; a *.env file like gotify's also
failed the .env prefix check.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…sitive

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
// go's verb list is closed: dependency + verify commands only. run/test/generate
// execute project-defined code; `go mod edit` can rewrite module requirements
// to arbitrary sources, so only the read/refresh mod subcommands are allowed.
const GO_SUBCOMMANDS = ['get', 'build', 'vet', 'fmt', 'version', 'list'];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: Build output can install executable Git hooks

Allowing go build with unrestricted flags admits commands such as go build -o .git/hooks/pre-commit ./cmd/payload. An attacker-controlled repository can use this to install its payload as an executable hook that runs during a later commit; reject -o or validate that its destination cannot target .git or other executable control paths.

@sarahxsanders
sarahxsanders merged commit 50965d7 into main Aug 21, 2026
17 checks passed
@sarahxsanders
sarahxsanders deleted the posthog-code/go-framework-support branch August 21, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants