Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

fix(agent): encode non-ascii gateway property headers - #3041

Closed
MarxWellB wants to merge 1 commit into
PostHog:mainfrom
MarxWellB:fix/non-ascii-gateway-headers
Closed

MarxWellB wants to merge 1 commit into
PostHog:mainfrom
MarxWellB:fix/non-ascii-gateway-headers

Conversation

@MarxWellB

Copy link
Copy Markdown

Problem

Slack-created PostHog Code tasks can fail when the task title contains non-ASCII characters. The original task title is forwarded as an x-posthog-property-task_title HTTP header value, and some HTTP clients reject header values containing characters outside the safe ASCII range.

The original title should remain unchanged for storage and UI display. The unsafe boundary is only when the title is serialized into gateway property headers.

Fixes PostHog/posthog#65950.

Changes

  • Preserve the existing newline-collapsing behavior to prevent header injection.
  • Keep printable ASCII characters unchanged.
  • Percent-encode all non-ASCII characters with encodeURIComponent.
  • Add regression coverage for smart quotes, emoji, accented characters, CJK characters, and the Danish-style input described in the issue.

Why encode instead of strip?

Stripping non-ASCII characters makes the header safe, but loses user context. Encoding keeps the value ASCII-safe while preserving the original information in a reversible representation.

Examples:

å  -> %C3%A5
é  -> %C3%A9
東京 -> %E6%9D%B1%E4%BA%AC
🚀 -> %F0%9F%9A%80

How did you test this?

  • pnpm --filter @posthog/agent test gateway.test.ts
  • pnpm --filter @posthog/agent typecheck — fails locally due unresolved internal workspace packages such as @posthog/shared, @posthog/git, and @posthog/enricher; no errors are reported in gateway.ts or gateway.test.ts.

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(agent): encode non-ascii gateway pro..." | Re-trigger Greptile

Comment thread packages/agent/src/utils/gateway.test.ts Outdated
@MarxWellB
MarxWellB force-pushed the fix/non-ascii-gateway-headers branch 2 times, most recently from 770af36 to 1375a41 Compare July 1, 2026 01:41
@MarxWellB
MarxWellB force-pushed the fix/non-ascii-gateway-headers branch from 1375a41 to 82ec8b2 Compare July 1, 2026 01:44
@charlesvien

Copy link
Copy Markdown
Member

Thanks for digging into this. Closing as superseded: main fixed the same bug in #3375 by transliterating header values to ASCII in packages/shared/src/posthog-property-headers.ts, and gateway.ts is now just a re-export of that module, so this branch can't be rebased onto the new location.

Percent-encoding also has two problems here: nothing decodes the values downstream, so titles would show up in analytics as caf%C3%A9, and encodeURIComponent throws on lone surrogates, turning a malformed title into a crash during session setup.

If preserving CJK/emoji fidelity matters, that would need a change in the shared module plus a decode step on the gateway side.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug report: posthog code - non-ascii slack task titles break header

2 participants