Skip to content

Conversation

@ogabrielluiz
Copy link
Contributor

@ogabrielluiz ogabrielluiz commented Jun 12, 2025

Summary by CodeRabbit

  • New Features
    • Enforced stricter authentication: valid API key or JWT is now always required for login, with clearer error handling.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 12, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The 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

File(s) Change Summary
src/backend/base/langflow/initial_setup/starter_projects/Memory Chatbot.json Refactored Memory component: split sender filtering into sender_type and sender inputs, added new method for text output (retrieve_messages_as_text), updated output logic to provide both text and DataFrame outputs, adjusted input defaults and visibility, and updated output declarations and internal method logic.
src/backend/base/langflow/services/auth/utils.py Removed deprecation warnings and fallback logic in authentication; now enforces valid API key or JWT for both HTTP and WebSocket authentication, raising errors when missing, and simplified control flow.

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
Loading
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
Loading
✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch fix-1.5-warning

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai bot changed the title @coderabbitai refactor(memory-chatbot): separate sender filtering and update outputs and auth Jun 12, 2025
@ogabrielluiz ogabrielluiz changed the title refactor(memory-chatbot): separate sender filtering and update outputs and auth feat(auth): update AUTO_LOGIN authentication to enforce API key or JWT requirement Jun 12, 2025
@github-actions github-actions bot added refactor Maintenance tasks and housekeeping enhancement New feature or request and removed refactor Maintenance tasks and housekeeping enhancement New feature or request labels Jun 12, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 issue

Runtime NameError risk from ApiKey in local variable annotation

ApiKey is imported only under TYPE_CHECKING, hence it is undefined at runtime.
Local-scope annotations are evaluated when the function executes (PEP 526), so the line

result: ApiKey | User | None

will raise NameError on the very first request that hits api_key_security.

Suggested fix – either import ApiKey unconditionally or avoid the annotation entirely:

-        result: ApiKey | User | None
+        # Only the user instance is returned by `check_key`
+        result: User | None

Alternatively, quote the type ("ApiKey") but that annotation is misleading because check_key returns the related User.

🧹 Nitpick comments (1)
src/backend/base/langflow/services/auth/utils.py (1)

97-105: Duplicate policy-violation block – extract constant / align wording

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between ab1ed8e and e87df0f.

📒 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_text output is correctly configured to use retrieve_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 dataframe output now correctly calls retrieve_messages_dataframe, returning messages as a DataFrame. Configuration matches the component definition.

Comment on lines 52 to 67
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)
Copy link
Contributor

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:

  1. Change the message to mention API keys only, or
  2. Add JWT detection here (e.g. delegate to get_current_user_by_jwt when 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.

@ogabrielluiz ogabrielluiz enabled auto-merge June 12, 2025 15:52
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 13, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 13, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 13, 2025
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail=(
"Since v1.5, AUTO_LOGIN requires a valid API key. Please update your authentication method."
Copy link
Collaborator

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?

Copy link
Contributor Author

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."
Copy link
Collaborator

Choose a reason for hiding this comment

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

.

@dosubot dosubot bot added lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jun 13, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 13, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 23, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 23, 2025
…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.
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 24, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 24, 2025
…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.
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 24, 2025
@ogabrielluiz ogabrielluiz added this pull request to the merge queue Jun 24, 2025
Merged via the queue into main with commit 3a3e205 Jun 24, 2025
66 checks passed
@ogabrielluiz ogabrielluiz deleted the fix-1.5-warning branch June 24, 2025 13:39
ogabrielluiz added a commit to bkatya2001/langflow that referenced this pull request Jun 24, 2025
…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"""
Copy link
Collaborator

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)?

Khurdhula-Harshavardhan pushed a commit to JigsawStack/langflow that referenced this pull request Jul 1, 2025
…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>
dev-thiago-oliver pushed a commit to vvidai/langflow that referenced this pull request Jul 5, 2025
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants