Skip to content

fix(flags): Pass project API key in remote_config requests #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 6, 2025

Conversation

haacked
Copy link
Collaborator

@haacked haacked commented Aug 4, 2025

Updates remote_config to pass the project api key in the token query string parameter. This is the same approach taken with local_evaluation. This ensures deterministic project routing.

@haacked haacked requested a review from a team August 4, 2025 22:20
@dmarticus dmarticus moved this to In Review in Feature Flags Aug 4, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR updates the remote configuration functionality in the PostHog Python SDK to align with backend API changes. The core modification switches the remote_config function from making GET requests to POST requests, and introduces a required project_api_key parameter for deterministic project selection and validation.

The changes span four files:

  1. posthog/request.py: The remote_config function is completely rewritten to use POST requests instead of GET. It now accepts a project_api_key parameter and includes both the personal API key (in Authorization header) and project API key (in request body) for proper authentication and project validation.

  2. posthog/client.py: The get_remote_config_payload method is updated to pass self.api_key as the project_api_key parameter when calling the remote_config function. This ensures that remote config requests include the necessary project identification.

  3. posthog/test/test_client.py: Test cases are updated to expect the new project_api_key parameter in remote_config function calls. The test mocking is adjusted to reflect the new API signature.

  4. remote_config_example.py: A new example script is added to demonstrate usage of the updated remote config functionality, showing how both project and personal API keys work together.

This change improves security by ensuring that personal API keys are properly validated against the expected project context, and provides more reliable routing for multi-project scenarios. The modification is part of a broader effort to standardize project identification across PostHog's API endpoints.

Confidence score: 2/5

  • This PR has significant implementation issues that could cause production problems
  • Score lowered due to anti-patterns in the request.py implementation and potential reliability concerns
  • The remote_config function bypasses the configured session and retry logic, imports modules inline, and may break existing functionality

4 files reviewed, 2 comments

Edit Code Review Bot Settings | Greptile

@andyzzhao andyzzhao self-requested a review August 5, 2025 18:35
Copy link

@andyzzhao andyzzhao left a comment

Choose a reason for hiding this comment

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

🚢

@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Aug 5, 2025
@haacked haacked changed the title fix(flags): Always pass project API key in remote_config requests fix(flags): Always pass project API key in remote_config and local_evaluation requests Aug 6, 2025
@haacked haacked changed the title fix(flags): Always pass project API key in remote_config and local_evaluation requests fix(flags): Always pass project API key in remote_config requests Aug 6, 2025
@haacked haacked force-pushed the haacked/remote-config-fix branch from eea00bb to 735bde8 Compare August 6, 2025 15:36
@haacked haacked force-pushed the haacked/remote-config-fix branch 2 times, most recently from 2625ff5 to 29ecfbe Compare August 6, 2025 20:41
@haacked haacked force-pushed the haacked/remote-config-fix branch from 29ecfbe to 19b1bcd Compare August 6, 2025 20:59
@haacked haacked changed the title fix(flags): Always pass project API key in remote_config requests fix(flags): Pass project API key in remote_config requests Aug 6, 2025
@haacked haacked force-pushed the haacked/remote-config-fix branch from 19b1bcd to b61cb20 Compare August 6, 2025 21:02
haacked added 3 commits August 6, 2025 14:13
Updates `remote_config` to pass the project api key in the token query string parameter. This is the same approach used by local_evaluation to ensure routing to the correct project.
Prepare for release with remote_config project API key fix
@haacked haacked force-pushed the haacked/remote-config-fix branch from 248f195 to 5815f35 Compare August 6, 2025 21:15
@haacked haacked enabled auto-merge (squash) August 6, 2025 21:15
@haacked haacked merged commit d25fae3 into master Aug 6, 2025
10 checks passed
@haacked haacked deleted the haacked/remote-config-fix branch August 6, 2025 21:17
@github-project-automation github-project-automation bot moved this from Approved to Done in Feature Flags Aug 6, 2025
haacked added a commit to PostHog/posthog-js that referenced this pull request Aug 7, 2025
…ect routing

This change ensures that remote config requests include the project API key as a query parameter,
enabling deterministic project routing when using personal API keys that have access to multiple projects.

Port of PostHog Python implementation: PostHog/posthog-python#303

Changes:
- Update remote config URL to include token parameter with project API key
- Add comprehensive test coverage for the new URL format
- Update changelog to document the fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants