Skip to content

feat: Add webhook user authentication under WEBHOOK_AUTH_ENABLE variable#9139

Merged
Cristhianzl merged 19 commits into
mainfrom
cz/webhook-auth
Aug 29, 2025
Merged

feat: Add webhook user authentication under WEBHOOK_AUTH_ENABLE variable#9139
Cristhianzl merged 19 commits into
mainfrom
cz/webhook-auth

Conversation

@Cristhianzl
Copy link
Copy Markdown
Member

@Cristhianzl Cristhianzl commented Jul 22, 2025

This pull request introduces webhook authentication enhancements, backend and frontend updates to support these changes, and improvements to testing and error handling. The key changes include implementing a new WEBHOOK_AUTH_ENABLE setting, modifying webhook execution logic to respect this setting, and updating the frontend to reflect the new authentication behavior.

Webhook Authentication Enhancements:

  • Added a WEBHOOK_AUTH_ENABLE setting in AuthSettings to toggle webhook authentication. When enabled, API key authentication is mandatory for webhook execution; otherwise, webhooks execute as the flow owner without authentication (src/backend/base/langflow/services/settings/auth.py).
  • Implemented get_webhook_user function to handle user authentication for webhooks based on the WEBHOOK_AUTH_ENABLE setting (src/backend/base/langflow/services/auth/utils.py).
  • Updated the webhook_run_flow endpoint to use get_webhook_user for determining the executing user (src/backend/base/langflow/api/v1/endpoints.py) [1] [2] [3].

Backend Updates:

  • Extended the ConfigResponse schema and its from_settings method to include the WEBHOOK_AUTH_ENABLE flag, ensuring the frontend is aware of the setting (src/backend/base/langflow/api/v1/schemas.py) [1] [2].
  • Added a new test suite for webhook behavior, covering scenarios such as valid/invalid API keys, unauthorized users, and the effect of the WEBHOOK_AUTH_ENABLE setting (src/backend/tests/unit/test_webhook.py) [1] [2].

Frontend Updates:

  • Updated the TextAreaComponent to use the webhookAuthEnable state from the utilityStore, ensuring the frontend reflects the authentication requirements for webhooks (src/frontend/src/components/core/parameterRenderComponent/components/textAreaComponent/index.tsx) [1] [2] [3] [4] [5].

Testing and Error Handling Improvements:

  • Removed unnecessary noqa comments (BLE001) from exception handling in tests for better readability and compliance (src/backend/tests/conftest.py, src/backend/tests/integration/components/astra/test_astra_component.py, src/backend/tests/locust/locustfile.py, src/backend/tests/unit/components/agents/test_agent_component.py) [1] [2] [3] [4] [5].

These changes collectively enhance the security and configurability of webhook execution while improving the maintainability of the codebase.

…r authentication

🔧 (endpoints.py): Update webhook_run_flow endpoint to use get_webhook_user for authentication
🔧 (utils.py): Add get_webhook_user function to handle webhook user authentication in services.auth
✅ (test_webhook.py): Add tests for webhook endpoint authentication and authorization
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 22, 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 webhook authentication logic was refactored to centralize user retrieval into a new asynchronous function, get_webhook_user, which handles API key validation and AUTO_LOGIN logic. The webhook endpoint was updated to use this function, and the associated tests were expanded and reorganized to cover different authentication and authorization scenarios more explicitly.

Changes

Files/Groups Change Summary
src/backend/base/langflow/api/v1/endpoints.py Refactored webhook endpoint to remove user dependency injection; now retrieves user via new get_webhook_user function.
src/backend/base/langflow/services/auth/utils.py Added get_webhook_user async function for webhook authentication; imports updated.
src/backend/tests/unit/test_webhook.py Split and expanded tests to cover API key enforcement, AUTO_LOGIN, valid/invalid key handling, and authorization scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant FastAPI
    participant AuthUtils
    participant FlowRunner

    Client->>FastAPI: POST /webhook/{flow_id_or_name}
    FastAPI->>AuthUtils: get_webhook_user(flow_id_or_name, request)
    AuthUtils-->>FastAPI: UserRead (if authorized) or HTTP 403
    FastAPI->>FlowRunner: simple_run_flow_task(..., api_key_user=UserRead)
    FlowRunner-->>FastAPI: Flow execution result
    FastAPI-->>Client: Response
Loading

Estimated code review effort

2 (~15 minutes)

Suggested labels

enhancement, size:L, lgtm

Suggested reviewers

  • deon-sanchez
  • mfortman11
  • lucaseduoli
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cz/webhook-auth

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 22, 2025
Copy link
Copy Markdown
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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e24202 and e27597a.

📒 Files selected for processing (3)
  • src/backend/base/langflow/api/v1/endpoints.py (4 hunks)
  • src/backend/base/langflow/services/auth/utils.py (2 hunks)
  • src/backend/tests/unit/test_webhook.py (2 hunks)
📓 Path-based instructions (3)
{src/backend/**/*.py,tests/**/*.py,Makefile}

📄 CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)

{src/backend/**/*.py,tests/**/*.py,Makefile}: Run make format_backend to format Python code before linting or committing changes
Run make lint to perform linting checks on backend Python code

Files:

  • src/backend/base/langflow/services/auth/utils.py
  • src/backend/base/langflow/api/v1/endpoints.py
  • src/backend/tests/unit/test_webhook.py
src/backend/tests/unit/**/*.py

📄 CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)

Test component integration within flows using create_flow, build_flow, and get_build_events utilities

Files:

  • src/backend/tests/unit/test_webhook.py
src/backend/tests/**/*.py

📄 CodeRabbit Inference Engine (.cursor/rules/testing.mdc)

src/backend/tests/**/*.py: Unit tests for backend code must be located in the 'src/backend/tests/' directory, with component tests organized by component subdirectory under 'src/backend/tests/unit/components/'.
Test files should use the same filename as the component under test, with an appropriate test prefix or suffix (e.g., 'my_component.py' → 'test_my_component.py').
Use the 'client' fixture (an async httpx.AsyncClient) for API tests in backend Python tests, as defined in 'src/backend/tests/conftest.py'.
When writing component tests, inherit from the appropriate base class in 'src/backend/tests/base.py' (ComponentTestBase, ComponentTestBaseWithClient, or ComponentTestBaseWithoutClient) and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping'.
Each test in backend Python test files should have a clear docstring explaining its purpose, and complex setups or mocks should be well-commented.
Test both sync and async code paths in backend Python tests, using '@pytest.mark.asyncio' for async tests.
Mock external dependencies appropriately in backend Python tests to isolate unit tests from external services.
Test error handling and edge cases in backend Python tests, including using 'pytest.raises' and asserting error messages.
Validate input/output behavior and test component initialization and configuration in backend Python tests.
Use the 'no_blockbuster' pytest marker to skip the blockbuster plugin in tests when necessary.
Be aware of ContextVar propagation in async tests; test both direct event loop execution and 'asyncio.to_thread' scenarios to ensure proper context isolation.
Test error handling by mocking internal functions using monkeypatch in backend Python tests.
Test resource cleanup in backend Python tests by using fixtures that ensure proper initialization and cleanup of resources.
Test timeout and performance constraints in backend Python tests using 'asyncio.wait_for' and timing assertions.
Test Langflow's Messag...

Files:

  • src/backend/tests/unit/test_webhook.py
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test webhook endpoints in backend Python tests by posting payloads and asserting correct processing and response codes.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test Langflow's REST API endpoints in backend Python tests using the async client fixture and asserting response codes and payloads.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-07-18T18:25:54.474Z
Learning: Applies to tests/**/*.py : Test authenticated API endpoints using logged_in_headers
src/backend/tests/unit/test_webhook.py (12)

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test webhook endpoints in backend Python tests by posting payloads and asserting correct processing and response codes.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.091Z
Learning: Applies to src/backend/tests/**/*.py : Use the 'client' fixture (an async httpx.AsyncClient) for API tests in backend Python tests, as defined in 'src/backend/tests/conftest.py'.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test components that require external APIs using appropriate pytest markers (e.g., 'api_key_required', 'no_blockbuster') and environment variables for API keys.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Mock external dependencies appropriately in backend Python tests to isolate unit tests from external services.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test Langflow's REST API endpoints in backend Python tests using the async client fixture and asserting response codes and payloads.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-07-18T18:25:54.474Z
Learning: Applies to tests/**/*.py : Mark tests that require real API keys with @pytest.mark.api_key_required and @pytest.mark.no_blockbuster

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Be aware of ContextVar propagation in async tests; test both direct event loop execution and 'asyncio.to_thread' scenarios to ensure proper context isolation.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-07-18T18:25:54.474Z
Learning: Applies to tests/**/*.py : Test authenticated API endpoints using logged_in_headers

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test real-time event streaming endpoints in backend Python tests by consuming and validating NDJSON event streams.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test both sync and async code paths in backend Python tests, using '@pytest.mark.asyncio' for async tests.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test flows using predefined JSON data and utility functions such as 'create_flow', 'build_flow', 'get_build_events', and 'consume_and_assert_stream' in backend Python tests.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-07-18T18:25:54.474Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities

🧰 Additional context used
📓 Path-based instructions (3)
{src/backend/**/*.py,tests/**/*.py,Makefile}

📄 CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)

{src/backend/**/*.py,tests/**/*.py,Makefile}: Run make format_backend to format Python code before linting or committing changes
Run make lint to perform linting checks on backend Python code

Files:

  • src/backend/base/langflow/services/auth/utils.py
  • src/backend/base/langflow/api/v1/endpoints.py
  • src/backend/tests/unit/test_webhook.py
src/backend/tests/unit/**/*.py

📄 CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)

Test component integration within flows using create_flow, build_flow, and get_build_events utilities

Files:

  • src/backend/tests/unit/test_webhook.py
src/backend/tests/**/*.py

📄 CodeRabbit Inference Engine (.cursor/rules/testing.mdc)

src/backend/tests/**/*.py: Unit tests for backend code must be located in the 'src/backend/tests/' directory, with component tests organized by component subdirectory under 'src/backend/tests/unit/components/'.
Test files should use the same filename as the component under test, with an appropriate test prefix or suffix (e.g., 'my_component.py' → 'test_my_component.py').
Use the 'client' fixture (an async httpx.AsyncClient) for API tests in backend Python tests, as defined in 'src/backend/tests/conftest.py'.
When writing component tests, inherit from the appropriate base class in 'src/backend/tests/base.py' (ComponentTestBase, ComponentTestBaseWithClient, or ComponentTestBaseWithoutClient) and provide the required fixtures: 'component_class', 'default_kwargs', and 'file_names_mapping'.
Each test in backend Python test files should have a clear docstring explaining its purpose, and complex setups or mocks should be well-commented.
Test both sync and async code paths in backend Python tests, using '@pytest.mark.asyncio' for async tests.
Mock external dependencies appropriately in backend Python tests to isolate unit tests from external services.
Test error handling and edge cases in backend Python tests, including using 'pytest.raises' and asserting error messages.
Validate input/output behavior and test component initialization and configuration in backend Python tests.
Use the 'no_blockbuster' pytest marker to skip the blockbuster plugin in tests when necessary.
Be aware of ContextVar propagation in async tests; test both direct event loop execution and 'asyncio.to_thread' scenarios to ensure proper context isolation.
Test error handling by mocking internal functions using monkeypatch in backend Python tests.
Test resource cleanup in backend Python tests by using fixtures that ensure proper initialization and cleanup of resources.
Test timeout and performance constraints in backend Python tests using 'asyncio.wait_for' and timing assertions.
Test Langflow's Messag...

Files:

  • src/backend/tests/unit/test_webhook.py
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test webhook endpoints in backend Python tests by posting payloads and asserting correct processing and response codes.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test Langflow's REST API endpoints in backend Python tests using the async client fixture and asserting response codes and payloads.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-07-18T18:25:54.474Z
Learning: Applies to tests/**/*.py : Test authenticated API endpoints using logged_in_headers
src/backend/tests/unit/test_webhook.py (12)

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test webhook endpoints in backend Python tests by posting payloads and asserting correct processing and response codes.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.091Z
Learning: Applies to src/backend/tests/**/*.py : Use the 'client' fixture (an async httpx.AsyncClient) for API tests in backend Python tests, as defined in 'src/backend/tests/conftest.py'.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test components that require external APIs using appropriate pytest markers (e.g., 'api_key_required', 'no_blockbuster') and environment variables for API keys.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Mock external dependencies appropriately in backend Python tests to isolate unit tests from external services.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test Langflow's REST API endpoints in backend Python tests using the async client fixture and asserting response codes and payloads.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-07-18T18:25:54.474Z
Learning: Applies to tests/**/*.py : Mark tests that require real API keys with @pytest.mark.api_key_required and @pytest.mark.no_blockbuster

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Be aware of ContextVar propagation in async tests; test both direct event loop execution and 'asyncio.to_thread' scenarios to ensure proper context isolation.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-07-18T18:25:54.474Z
Learning: Applies to tests/**/*.py : Test authenticated API endpoints using logged_in_headers

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test real-time event streaming endpoints in backend Python tests by consuming and validating NDJSON event streams.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test both sync and async code paths in backend Python tests, using '@pytest.mark.asyncio' for async tests.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-07-21T14:16:14.092Z
Learning: Applies to src/backend/tests/**/*.py : Test flows using predefined JSON data and utility functions such as 'create_flow', 'build_flow', 'get_build_events', and 'consume_and_assert_stream' in backend Python tests.

Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-07-18T18:25:54.474Z
Learning: Applies to src/backend/tests/unit/**/*.py : Test component integration within flows using create_flow, build_flow, and get_build_events utilities

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Optimize new Python code in this PR
🔇 Additional comments (10)
src/backend/base/langflow/services/auth/utils.py (1)

10-10: LGTM: Import addition for new functionality

The Request import is correctly added to support the new get_webhook_user function parameter.

src/backend/base/langflow/api/v1/endpoints.py (4)

45-45: LGTM: Import addition for webhook authentication

The get_webhook_user import is correctly added to support the new webhook authentication logic.


394-399: LGTM: Function signature updated for centralized authentication

The addition of the flow_id_or_name parameter and removal of the user dependency injection aligns well with the new centralized webhook authentication approach. This provides more control over the authentication flow.


418-421: LGTM: Centralized webhook authentication implementation

The call to get_webhook_user is correctly implemented with proper async/await usage and clear variable naming. This centralizes the webhook authentication logic as intended.


453-453: LGTM: Consistent user parameter usage

The webhook_user is correctly passed as the api_key_user parameter to maintain consistency with the background task function signature.

src/backend/tests/unit/test_webhook.py (5)

11-22: LGTM: Well-structured test for API key requirement

The test properly validates the default authentication behavior with clear assertions and appropriate error message checking. The docstring clearly explains the test purpose.


24-41: LGTM: Comprehensive test with proper resource management

The test effectively validates webhook functionality with valid API key authentication. The use of temporary files with proper cleanup and validation of both HTTP response and file creation demonstrates good testing practices.


43-56: LGTM: Authorization failure test with clear validation

The test properly simulates and validates authorization failure scenarios with appropriate HTTP status checking and error message validation.


70-88: LGTM: Proper mocking for AUTO_LOGIN scenario testing

The test correctly uses mocking to simulate the AUTO_LOGIN=true scenario and validates that webhook execution works without an API key. The mocking approach is appropriate and the test is well-structured.


90-106: LGTM: Comprehensive authentication testing with different payloads

The test effectively validates authentication requirements regardless of payload content, testing both failure and success scenarios with appropriate assertions and clear documentation.

Comment thread src/backend/base/langflow/services/auth/utils.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@SonicDMG SonicDMG temporarily deployed to cz/webhook-auth - langflow-manual-install PR #9139 July 28, 2025 17:09 — with Render Destroyed
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jul 28, 2025
Comment thread src/backend/base/langflow/services/auth/utils.py Outdated
Copy link
Copy Markdown
Contributor

@ogabrielluiz ogabrielluiz left a comment

Choose a reason for hiding this comment

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

I don't understand why this is needed.

Comment thread src/backend/base/langflow/services/auth/utils.py Outdated
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
@Cristhianzl
Copy link
Copy Markdown
Member Author

Cristhianzl commented Jul 28, 2025

I don't understand why this is needed.

Our webhook has no security in place.
We don't require a security token to execute it.
This means that in a production environment, if a user discovers the Langflow webhook endpoint that triggers the webhook, they can run it whenever they want!

…ecurity function for better code reuse and readability
@Cristhianzl Cristhianzl added this pull request to the merge queue Aug 27, 2025
github-merge-queue Bot pushed a commit that referenced this pull request Aug 27, 2025
…ble (#9139)

* 📝 (endpoints.py): Add get_webhook_user function to handle webhook user authentication
🔧 (endpoints.py): Update webhook_run_flow endpoint to use get_webhook_user for authentication
🔧 (utils.py): Add get_webhook_user function to handle webhook user authentication in services.auth
✅ (test_webhook.py): Add tests for webhook endpoint authentication and authorization

* Update src/backend/base/langflow/services/auth/utils.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* [autofix.ci] apply automated fixes

* Update src/backend/base/langflow/services/auth/utils.py

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>

* 🔧 (utils.py): refactor authentication logic to use existing api_key_security function for better code reuse and readability

* [autofix.ci] apply automated fixes

* 📝 (endpoints.py): Update ConfigResponse class to include webhook_auth_enable field and modify from_settings method to accept auth_settings parameter
📝 (endpoints.py): Update get_config function to pass auth_settings to ConfigResponse.from_settings method
📝 (utils.py): Update get_webhook_user function to use WEBHOOK_AUTH_ENABLE setting for authentication logic
📝 (auth.py): Add WEBHOOK_AUTH_ENABLE setting to AuthSettings class
📝 (index.tsx): Add webhookAuthEnable state and setWebhookAuthEnable function to utilityStore
📝 (use-get-config.ts): Update useGetConfig hook to set webhook_auth_enable value from API response
📝 (get-curl-code.tsx): Update getCurlWebhookCode function to use webhookAuthEnable instead of isAuth parameter
📝 (utilityStore.ts): Add webhookAuthEnable state and setWebhookAuthEnable function to utilityStore
📝 (index.ts): Update GetCodeType type to use webhookAuthEnable instead of isAuth parameter

* refactor: Simplify error messages in get_webhook_user function

- Updated HTTPException messages for flow not found and access denied scenarios to be more concise and user-friendly.
- Improved logging for invalid API key validation to enhance clarity.

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 27, 2025
@Cristhianzl Cristhianzl enabled auto-merge August 28, 2025 02:17
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 28, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 28, 2025

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 6%
6.47% (1680/25942) 3.51% (690/19621) 3.47% (194/5587)

Unit Test Results

Tests Skipped Failures Errors Time
682 0 💤 0 ❌ 0 🔥 11.978s ⏱️

@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 28, 2025

Codecov Report

❌ Patch coverage is 57.62712% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 34.62%. Comparing base (2313435) to head (7589d65).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/backend/base/langflow/services/auth/utils.py 62.79% 16 Missing ⚠️
...c/controllers/API/queries/config/use-get-config.ts 0.00% 3 Missing ⚠️
...ontend/src/modals/apiModal/utils/get-curl-code.tsx 0.00% 3 Missing ⚠️
...erComponent/components/textAreaComponent/index.tsx 0.00% 2 Missing ⚠️
src/frontend/src/stores/utilityStore.ts 0.00% 1 Missing ⚠️

❌ Your project status has failed because the head coverage (5.81%) is below the target coverage (10.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #9139      +/-   ##
==========================================
- Coverage   34.69%   34.62%   -0.07%     
==========================================
  Files        1209     1209              
  Lines       57115    57159      +44     
  Branches     5419     5418       -1     
==========================================
- Hits        19818    19794      -24     
- Misses      37153    37221      +68     
  Partials      144      144              
Flag Coverage Δ
backend 56.06% <68.00%> (-0.15%) ⬇️
frontend 5.81% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/backend/base/langflow/api/v1/endpoints.py 58.71% <100.00%> (ø)
src/backend/base/langflow/api/v1/schemas.py 96.06% <100.00%> (+0.01%) ⬆️
...rc/backend/base/langflow/services/settings/auth.py 87.95% <100.00%> (+0.29%) ⬆️
src/frontend/src/stores/utilityStore.ts 0.00% <0.00%> (ø)
...erComponent/components/textAreaComponent/index.tsx 0.00% <0.00%> (ø)
...c/controllers/API/queries/config/use-get-config.ts 0.00% <0.00%> (ø)
...ontend/src/modals/apiModal/utils/get-curl-code.tsx 61.05% <0.00%> (ø)
src/backend/base/langflow/services/auth/utils.py 54.24% <62.79%> (+1.21%) ⬆️

... and 17 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…conditions being tested

📝 (test_webhook.py): update test descriptions to improve clarity and consistency with actual test conditions
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 28, 2025
…when flow owner is not found in get_webhook_user function. Added explicit check and raise HTTPException with appropriate status code and detail message.
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 28, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 29, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Aug 29, 2025
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fast-track Skip tests and sends PR into the merge queue lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants