Skip to content

ingest: encode PostHog project path segment - #998

Open
sdivyanshu90 wants to merge 1 commit into
experientiallabs:mainfrom
sdivyanshu90:fix/encode-posthog-project-id
Open

sdivyanshu90 wants to merge 1 commit into
experientiallabs:mainfrom
sdivyanshu90:fix/encode-posthog-project-id

Conversation

@sdivyanshu90

@sdivyanshu90 sdivyanshu90 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Why

PostHogPullRequest.project_id accepts any nonblank string, but pull_posthog_traces inserted it directly into /api/projects/{project_id}/query/. Reserved and Unicode characters could therefore change the authorized request target instead of remaining one project path segment.

Closes #997.

What

  • Percent-encode the PostHog project ID with an empty safe-character set before endpoint composition, including complete . and .. segments.
  • Preserve the original project ID for source identity.
  • Add a dedicated posthog_pull_test.py injected-client regression covering path, query, fragment, percent, space, and Unicode characters.

Validation

  • Before the fix, test_project_id_is_encoded_as_one_url_path_segment failed with the raw project ID in the captured URL.
  • uv run --no-sync pytest -q exp/simulation/ingest/posthog_pull_test.py exp/simulation/ingest/posthog_canonical_test.py: 21 passed in 1.21s
  • uv run --no-sync ruff check .: passed
  • uv run --no-sync ruff format --check .: 859 files already formatted
  • uv run --no-sync ty check: passed

Non-goals

This change does not alter PostHog host validation, credentials, HogQL construction, response handling, or source identity.

@sdivyanshu90

Copy link
Copy Markdown
Contributor Author

Hi @SilenNaihin, could you please review this when you have a chance? It keeps PostHog project IDs within one encoded path segment and adds a focused transport regression. Thanks!

@superagent-security

Copy link
Copy Markdown

Superagent didn't find any vulnerabilities or security issues in this PR.

@greptile-apps

greptile-apps Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the previously reported dot-segment request-target issue is fully fixed.

Summary

The PR safely confines arbitrary PostHog project IDs to one URL path segment while retaining the original identifier for source identity.

  • Percent-encodes reserved, whitespace, percent, and Unicode characters before endpoint composition.
  • Explicitly encodes complete . and .. segments to prevent HTTP path normalization.
  • Adds focused regression coverage for reserved characters, Unicode, and both dot-segment cases.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[Original project ID] --> B[Percent-encode path segment]
    B --> C{Complete dot segment?}
    C -- Yes --> D[Encode periods as %2E]
    C -- No --> E[Use encoded segment]
    D --> F[Compose PostHog query endpoint]
    E --> F
    A --> G[Preserve original source identity]
Loading

Reviews (3) · Last reviewed commit: "ingest: encode PostHog project path segm..."

Comment thread exp/simulation/ingest/posthog_pull.py
@sdivyanshu90
sdivyanshu90 force-pushed the fix/encode-posthog-project-id branch from dbbcc14 to 6b78528 Compare September 16, 2026 06:34
@sdivyanshu90
sdivyanshu90 force-pushed the fix/encode-posthog-project-id branch from 6b78528 to 55dfdc3 Compare September 16, 2026 06:39
@sdivyanshu90

Copy link
Copy Markdown
Contributor Author

@kfallah Could you please review this PR whenever you have some time? Thanks

@sdivyanshu90

Copy link
Copy Markdown
Contributor Author

Hi @SilenNaihin @kfallah, could you please review this PR whenever you have some time. Thanks!

This branch has not been deployed

No deployments
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.

PostHog project IDs can alter the query request target

1 participant