RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Feat: Add OAuth `state` parameter for CSRF protection (#7709)
Chaoxi Weng6ed81d6774c4
diff --git a/api/apps/auth/oauth.py b/api/apps/auth/oauth.pyindex a908e81ea0..6f7e0e5b54 100644--- a/api/apps/auth/oauth.py+++ b/api/apps/auth/oauth.py@@ -45,7 +45,7 @@ class OAuthClient:self.http_request_timeout = 7- def get_authorization_url(self):+ def get_authorization_url(self, state=None):"""Generate the authorization URL for user login."""@@ -56,6 +56,8 @@ class OAuthClient:}if self.scope:params["scope"] = self.scope+ if state:+ params["state"] = stateauthorization_url = f"{self.authorization_url}?{urllib.parse.urlencode(params)}"return authorization_urldiff --git a/api/apps/user_app.py b/api/apps/user_app.pyindex ddca410182..401d6977d1 100644--- a/api/apps/user_app.py+++ b/api/apps/user_app.py@@ -146,7 +146,9 @@ def oauth_login(channel):raise ValueError(f"Invalid channel name: {channel}")auth_cli = get_auth_client(channel_config)- auth_url = auth_cli.get_authorization_url()+ state = get_uuid()+ session["oauth_state"] = state+ auth_url = auth_cli.get_authorization_url(state)return redirect(auth_url)@@ -161,6 +163,12 @@ def oauth_callback(channel):raise ValueError(f"Invalid channel name: {channel}")auth_cli = get_auth_client(channel_config)+ # Check the state+ state = request.args.get("state")+ if not state or state != session.get("oauth_state"):+ return redirect("/?error=invalid_state")+ session.pop("oauth_state", None)+# Obtain the authorization codecode = request.args.get("code")if not code: