-
Notifications
You must be signed in to change notification settings - Fork 8.2k
feat(auth): update AUTO_LOGIN authentication to enforce API key or JWT requirement #8513
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
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe Memory Chatbot component was refactored to separate sender filtering into sender type and explicit sender inputs, and its outputs were expanded to include both formatted text and DataFrame representations of messages. Authentication logic was updated to enforce stricter API key or JWT requirements, removing fallback behaviors and deprecation warnings. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MemoryComponent
User->>MemoryComponent: Store message (with sender_type, sender, message)
MemoryComponent->>MemoryComponent: store_message()
MemoryComponent-->>User: Confirmation (Message)
User->>MemoryComponent: Retrieve messages (with sender_type, sender)
alt Retrieve as text
MemoryComponent->>MemoryComponent: retrieve_messages_as_text()
MemoryComponent-->>User: Formatted Message (text)
else Retrieve as DataFrame
MemoryComponent->>MemoryComponent: retrieve_messages_dataframe()
MemoryComponent-->>User: DataFrame
end
sequenceDiagram
participant Client
participant AuthUtils
Client->>AuthUtils: Request (API key/JWT missing or invalid)
alt AUTO_LOGIN enabled
AuthUtils-->>Client: Error (HTTP 403 or WebSocket policy violation)
else Valid API key/JWT
AuthUtils->>AuthUtils: check_key()
AuthUtils-->>Client: Proceed
end
✨ Finishing Touches🧪 Generate Unit Tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
src/backend/base/langflow/services/auth/utils.py (1)
42-44:⚠️ Potential issueRuntime
NameErrorrisk fromApiKeyin local variable annotation
ApiKeyis imported only underTYPE_CHECKING, hence it is undefined at runtime.
Local-scope annotations are evaluated when the function executes (PEP 526), so the lineresult: ApiKey | User | Nonewill raise
NameErroron the very first request that hitsapi_key_security.Suggested fix – either import
ApiKeyunconditionally or avoid the annotation entirely:- result: ApiKey | User | None + # Only the user instance is returned by `check_key` + result: User | NoneAlternatively, quote the type (
"ApiKey") but that annotation is misleading becausecheck_keyreturns the relatedUser.
🧹 Nitpick comments (1)
src/backend/base/langflow/services/auth/utils.py (1)
97-105: Duplicate policy-violation block – extract constant / align wordingThe WebSocket branch duplicates the exact validation/error wording introduced for HTTP (lines 52-60). Consider:
POLICY_MSG_REQUIRE_KEY = ( "Since v1.5, AUTO_LOGIN requires a valid API key." " Please update your authentication method." )and reuse it in both places to keep wording in sync and avoid future drift.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/backend/base/langflow/initial_setup/starter_projects/Memory Chatbot.json(4 hunks)src/backend/base/langflow/services/auth/utils.py(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/backend/base/langflow/services/auth/utils.py (2)
src/backend/base/langflow/services/database/models/api_key/crud.py (1)
check_key(52-61)src/backend/base/langflow/__main__.py (1)
api_key(568-615)
🔇 Additional comments (2)
src/backend/base/langflow/initial_setup/starter_projects/Memory Chatbot.json (2)
856-866: Approve addition of text output mapping.The new
messages_textoutput is correctly configured to useretrieve_messages_as_text, providing the formatted message history as a Message object. Method exists and aligns with the updated component API.
868-870: Approve DataFrame output mapping.The
dataframeoutput now correctly callsretrieve_messages_dataframe, returning messages as a DataFrame. Configuration matches the component definition.
| if not query_param and not header_param: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_403_FORBIDDEN, | ||
| detail=( | ||
| "Since v1.5, AUTO_LOGIN requires a valid API key or JWT." | ||
| " Please update your authentication method." | ||
| ), | ||
| ) | ||
| result = await check_key(db, query_param or header_param) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Error message promises JWT support that this branch cannot fulfil
The new 403 block states “AUTO_LOGIN requires a valid API key or JWT.” but immediately afterwards you call check_key, which can validate API keys only. Supplying a JWT through x-api-key will still trigger the Invalid or missing API key path.
Either:
- Change the message to mention API keys only, or
- Add JWT detection here (e.g. delegate to
get_current_user_by_jwtwhen the token looks like a JWT).
Keeping the message as-is will confuse users and support teams.
🤖 Prompt for AI Agents
In src/backend/base/langflow/services/auth/utils.py around lines 52 to 60, the
error message incorrectly states that AUTO_LOGIN requires a valid API key or
JWT, but the code only validates API keys via check_key. To fix this, either
update the error message to mention only API keys or enhance the logic to detect
JWT tokens and delegate validation to get_current_user_by_jwt when a JWT is
supplied, ensuring the message matches the actual validation performed.
src/backend/base/langflow/initial_setup/starter_projects/Memory Chatbot.json
Show resolved
Hide resolved
| raise HTTPException( | ||
| status_code=status.HTTP_403_FORBIDDEN, | ||
| detail=( | ||
| "Since v1.5, AUTO_LOGIN requires a valid API key. Please update your authentication method." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we include LANGFLOW_ prefix? LANGFLOW_AUTO_LOGIN?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
| raise WebSocketException( | ||
| code=status.WS_1008_POLICY_VIOLATION, | ||
| reason=( | ||
| "Since v1.5, AUTO_LOGIN requires a valid API key. Please update your authentication method." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.
…integration tests * Implemented a helper function to obtain a JWT token for API requests, enhancing the security of the integration tests. * Updated the test for starter projects to include the token in API requests, ensuring proper authentication during testing.
…ndency * Introduced `get_current_user_mcp` function for MCP-specific user authentication, allowing fallback to username lookup when no API key is provided. * Added `get_current_active_user_mcp` dependency to manage active user checks for MCP, ensuring proper integration with the authentication flow.
…cp project endpoints * Updated project-related API endpoints to use CurrentActiveMCPUser for user authentication, enhancing clarity and consistency in user management. * Removed unused imports and dependencies related to the previous user authentication method, streamlining the codebase.
…T requirement (langflow-ai#8513) * feat(auth): update AUTO_LOGIN authentication to enforce API key or JWT requirement * Removed deprecated warning messages and implemented explicit HTTP exceptions for missing API key or JWT in both API and WebSocket authentication methods. * Enhanced error handling to ensure compliance with the new authentication requirements introduced in v1.5. * fix(auth): refine error message for AUTO_LOGIN API key requirement * Updated the error message in the API key security function to clarify that AUTO_LOGIN requires a valid API key, removing the mention of JWT for consistency with the latest authentication requirements. * feat(auth): introduce SKIP_AUTH_AUTO_LOGIN setting for enhanced authentication flexibility * Added a new configuration option `SKIP_AUTH_AUTO_LOGIN` to the AuthSettings class, allowing the application to bypass API key validation for auto login. * Updated the API and WebSocket security functions to utilize this setting, improving error handling and providing a fallback for superuser credentials when authentication is skipped. * refactor(auth): rename SKIP_AUTH_AUTO_LOGIN to skip_auth_auto_login for consistency * Updated the `SKIP_AUTH_AUTO_LOGIN` setting in the `AuthSettings` class to `skip_auth_auto_login` to follow Python naming conventions. * Adjusted references in the API and WebSocket security functions to use the new attribute name, ensuring consistent behavior across the authentication logic. * feat(auth): add deprecation warning for SKIP_AUTH_AUTO_LOGIN removal * Introduced a warning log in both API and WebSocket security functions to inform users that the `LANGFLOW_SKIP_AUTH_AUTO_LOGIN` feature will be removed in version 1.6, prompting necessary updates to authentication methods. * feat(auth): enhance deprecation warnings for AUTO_LOGIN features * Added constants for deprecation warning and error messages related to `LANGFLOW_SKIP_AUTH_AUTO_LOGIN` and `AUTO_LOGIN` requirements, improving code maintainability and clarity. * Updated API and WebSocket security functions to utilize these constants for logging and exception handling, ensuring consistent messaging across authentication methods. * fix(auth): update AUTO_LOGIN_ERROR message to include LANGFLOW_SKIP_AUTH_AUTO_LOGIN usage * fix(auth): correct logic for API key validation in WebSocket security function * Adjusted the conditional flow in the `ws_api_key_security` function to ensure that the API key is checked only when necessary, improving the clarity and correctness of the authentication logic. * [autofix.ci] apply automated fixes * feat(tests): add authentication token retrieval for starter projects integration tests * Implemented a helper function to obtain a JWT token for API requests, enhancing the security of the integration tests. * Updated the test for starter projects to include the token in API requests, ensuring proper authentication during testing. * feat(auth): add MCP-specific user authentication and active user dependency * Introduced `get_current_user_mcp` function for MCP-specific user authentication, allowing fallback to username lookup when no API key is provided. * Added `get_current_active_user_mcp` dependency to manage active user checks for MCP, ensuring proper integration with the authentication flow. * refactor(api): replace user dependency with CurrentActiveMCPUser in mcp project endpoints * Updated project-related API endpoints to use CurrentActiveMCPUser for user authentication, enhancing clarity and consistency in user management. * Removed unused imports and dependencies related to the previous user authentication method, streamlining the codebase. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
|
|
||
| skip_auth_auto_login: bool = True | ||
| """If True, the application will skip the authentication auto login, set this to False to revert to pre-v1.5 | ||
| behavior. This will be removed in v1.6""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is True by default, isn't the behavior unchanged (i.e. it's the same as pre-v1.5 behavior)?
…T requirement (langflow-ai#8513) * feat(auth): update AUTO_LOGIN authentication to enforce API key or JWT requirement * Removed deprecated warning messages and implemented explicit HTTP exceptions for missing API key or JWT in both API and WebSocket authentication methods. * Enhanced error handling to ensure compliance with the new authentication requirements introduced in v1.5. * fix(auth): refine error message for AUTO_LOGIN API key requirement * Updated the error message in the API key security function to clarify that AUTO_LOGIN requires a valid API key, removing the mention of JWT for consistency with the latest authentication requirements. * feat(auth): introduce SKIP_AUTH_AUTO_LOGIN setting for enhanced authentication flexibility * Added a new configuration option `SKIP_AUTH_AUTO_LOGIN` to the AuthSettings class, allowing the application to bypass API key validation for auto login. * Updated the API and WebSocket security functions to utilize this setting, improving error handling and providing a fallback for superuser credentials when authentication is skipped. * refactor(auth): rename SKIP_AUTH_AUTO_LOGIN to skip_auth_auto_login for consistency * Updated the `SKIP_AUTH_AUTO_LOGIN` setting in the `AuthSettings` class to `skip_auth_auto_login` to follow Python naming conventions. * Adjusted references in the API and WebSocket security functions to use the new attribute name, ensuring consistent behavior across the authentication logic. * feat(auth): add deprecation warning for SKIP_AUTH_AUTO_LOGIN removal * Introduced a warning log in both API and WebSocket security functions to inform users that the `LANGFLOW_SKIP_AUTH_AUTO_LOGIN` feature will be removed in version 1.6, prompting necessary updates to authentication methods. * feat(auth): enhance deprecation warnings for AUTO_LOGIN features * Added constants for deprecation warning and error messages related to `LANGFLOW_SKIP_AUTH_AUTO_LOGIN` and `AUTO_LOGIN` requirements, improving code maintainability and clarity. * Updated API and WebSocket security functions to utilize these constants for logging and exception handling, ensuring consistent messaging across authentication methods. * fix(auth): update AUTO_LOGIN_ERROR message to include LANGFLOW_SKIP_AUTH_AUTO_LOGIN usage * fix(auth): correct logic for API key validation in WebSocket security function * Adjusted the conditional flow in the `ws_api_key_security` function to ensure that the API key is checked only when necessary, improving the clarity and correctness of the authentication logic. * [autofix.ci] apply automated fixes * feat(tests): add authentication token retrieval for starter projects integration tests * Implemented a helper function to obtain a JWT token for API requests, enhancing the security of the integration tests. * Updated the test for starter projects to include the token in API requests, ensuring proper authentication during testing. * feat(auth): add MCP-specific user authentication and active user dependency * Introduced `get_current_user_mcp` function for MCP-specific user authentication, allowing fallback to username lookup when no API key is provided. * Added `get_current_active_user_mcp` dependency to manage active user checks for MCP, ensuring proper integration with the authentication flow. * refactor(api): replace user dependency with CurrentActiveMCPUser in mcp project endpoints * Updated project-related API endpoints to use CurrentActiveMCPUser for user authentication, enhancing clarity and consistency in user management. * Removed unused imports and dependencies related to the previous user authentication method, streamlining the codebase. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
…T requirement (langflow-ai#8513) * feat(auth): update AUTO_LOGIN authentication to enforce API key or JWT requirement * Removed deprecated warning messages and implemented explicit HTTP exceptions for missing API key or JWT in both API and WebSocket authentication methods. * Enhanced error handling to ensure compliance with the new authentication requirements introduced in v1.5. * fix(auth): refine error message for AUTO_LOGIN API key requirement * Updated the error message in the API key security function to clarify that AUTO_LOGIN requires a valid API key, removing the mention of JWT for consistency with the latest authentication requirements. * feat(auth): introduce SKIP_AUTH_AUTO_LOGIN setting for enhanced authentication flexibility * Added a new configuration option `SKIP_AUTH_AUTO_LOGIN` to the AuthSettings class, allowing the application to bypass API key validation for auto login. * Updated the API and WebSocket security functions to utilize this setting, improving error handling and providing a fallback for superuser credentials when authentication is skipped. * refactor(auth): rename SKIP_AUTH_AUTO_LOGIN to skip_auth_auto_login for consistency * Updated the `SKIP_AUTH_AUTO_LOGIN` setting in the `AuthSettings` class to `skip_auth_auto_login` to follow Python naming conventions. * Adjusted references in the API and WebSocket security functions to use the new attribute name, ensuring consistent behavior across the authentication logic. * feat(auth): add deprecation warning for SKIP_AUTH_AUTO_LOGIN removal * Introduced a warning log in both API and WebSocket security functions to inform users that the `LANGFLOW_SKIP_AUTH_AUTO_LOGIN` feature will be removed in version 1.6, prompting necessary updates to authentication methods. * feat(auth): enhance deprecation warnings for AUTO_LOGIN features * Added constants for deprecation warning and error messages related to `LANGFLOW_SKIP_AUTH_AUTO_LOGIN` and `AUTO_LOGIN` requirements, improving code maintainability and clarity. * Updated API and WebSocket security functions to utilize these constants for logging and exception handling, ensuring consistent messaging across authentication methods. * fix(auth): update AUTO_LOGIN_ERROR message to include LANGFLOW_SKIP_AUTH_AUTO_LOGIN usage * fix(auth): correct logic for API key validation in WebSocket security function * Adjusted the conditional flow in the `ws_api_key_security` function to ensure that the API key is checked only when necessary, improving the clarity and correctness of the authentication logic. * [autofix.ci] apply automated fixes * feat(tests): add authentication token retrieval for starter projects integration tests * Implemented a helper function to obtain a JWT token for API requests, enhancing the security of the integration tests. * Updated the test for starter projects to include the token in API requests, ensuring proper authentication during testing. * feat(auth): add MCP-specific user authentication and active user dependency * Introduced `get_current_user_mcp` function for MCP-specific user authentication, allowing fallback to username lookup when no API key is provided. * Added `get_current_active_user_mcp` dependency to manage active user checks for MCP, ensuring proper integration with the authentication flow. * refactor(api): replace user dependency with CurrentActiveMCPUser in mcp project endpoints * Updated project-related API endpoints to use CurrentActiveMCPUser for user authentication, enhancing clarity and consistency in user management. * Removed unused imports and dependencies related to the previous user authentication method, streamlining the codebase. --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Summary by CodeRabbit