mirror of
https://github.com/AJaySi/ALwrity.git
synced 2026-04-25 00:45:54 +03:00
[PR #435] Harden AI generation endpoints to use token-derived user identity #741
Labels
No labels
AI Content Agents
AI Content Strategy
AI Content planning
AI Marketing Tools
AI SEO
AI personalization
AI writer
ALwrity Copi-lot
Alwrity web search
Anthropic
DeepSeek
Gemini AI
Integration
LLM
OnBoarding
OnBoarding
RAG knowledgebase Memory
bug
documentation
enhancement
good first issue
help wanted
invalid
openai
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ALwrity#741
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/AJaySi/ALwrity/pull/435
Author: @AJaySi
Created: 3/12/2026
Status: 🔄 Open
Base:
main← Head:codex/refactor-user-id-handling-in-api-routes-v4hrgc📝 Commits (1)
3bffa8cHarden AI generation endpoints to use authenticated user claims📊 Changes
2 files changed (+94 additions, -7 deletions)
View changed files
📝
backend/api/content_planning/api/content_strategy/endpoints/ai_generation_endpoints.py(+37 -7)➕
backend/security_test_ai_generation_endpoints_auth.py(+57 -0)📄 Description
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
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.