Harden AI generation endpoints to use token-derived user identity#435
Open
Harden AI generation endpoints to use token-derived user identity#435
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
user_idvalues to public AI generation and retrieval routes.id/clerk_user_id) and surface an authentication error when missing.Description
current_user: Dict[str, Any] = Depends(get_current_user)to public AI endpoints and removed client-provideduser_idparameters from routes such asgenerate_comprehensive_strategy,generate_strategy_component,get_strategy_generation_status,generate_comprehensive_strategy_polling,get_strategy_generation_status_by_task, andget_latest_generated_strategy._get_authenticated_user_id(current_user)helper to consistently extract the authenticated user id (string) from token claims and raiseHTTPException(status_code=401)when missing.user_idbehavior (e.g.request.get("user_id", 1)and query default user IDs) and ensured downstream calls use the authenticateduser_idstring; removed an unusedQueryimport.403when the authenticated user does not own the requested task/strategy), and addedcurrent_userchecks tooptimize_existing_strategy.backend/security_test_ai_generation_endpoints_auth.pythat verify route signatures, enforcement of token-deriveduser_id, task-owner authorization, and the401on missing authenticated id.Testing
pytest -q backend/security_test_ai_generation_endpoints_auth.py, which executed the new auth-hardening assertions and all tests passed (4 passed).python -m compileall backend/api/content_planning/api/content_strategy/endpoints/ai_generation_endpoints.py backend/security_test_ai_generation_endpoints_auth.pyto validate modules compile successfully (succeeded).Codex Task