Skip to content

Conversation

david-menloai
Copy link
Contributor

@david-menloai david-menloai commented Jun 3, 2025

This pull request introduces a new feature for managing trusted hosts in the API server, enhancing security by allowing only specified hosts to access the server. It includes changes across the backend and frontend to support this functionality.

Backend Changes (Security Enhancements)

  • Added a trusted_hosts parameter to the start_server function and ProxyConfig struct to store and pass the list of trusted hosts. (src-tauri/src/core/cmd.rs, src-tauri/src/core/server.rs) [1] [2] [3]
  • Implemented host header validation in the proxy_request function to block requests from untrusted hosts. (src-tauri/src/core/server.rs)
  • Added a helper function is_valid_host to validate host headers against default and user-configured trusted hosts. (src-tauri/src/core/server.rs)

Frontend Changes (User Interface and State Management)

  • Introduced a TrustedHostsInput component for users to manage trusted hosts via the UI. (web-app/src/containers/TrustedHostsInput.tsx)
  • Updated the useLocalApiServer hook to include state management for trusted hosts, with methods to add, remove, and set hosts. (web-app/src/hooks/useLocalApiServer.ts) [1] [2]
  • Integrated the TrustedHostsInput component into the Local API Server settings page, allowing users to configure trusted hosts. (web-app/src/routes/settings/local-api-server.tsx) [1] [2] [3] [4]
image

Important

Enhance API server security by adding trusted host management, including backend validation and frontend configuration.

  • Backend Changes:
    • Added trusted_hosts parameter to start_server function and ProxyConfig struct in cmd.rs and server.rs.
    • Implemented host header validation in proxy_request function in server.rs to block untrusted hosts.
    • Added is_valid_host function in server.rs to validate host headers.
  • Frontend Changes:
    • Added TrustedHostsInput component in TrustedHostsInput.tsx for managing trusted hosts via UI.
    • Updated useLocalApiServer hook in useLocalApiServer.ts to manage trusted hosts state.
    • Integrated TrustedHostsInput into settings page in local-api-server.tsx for user configuration.

This description was created by Ellipsis for b674a52. You can customize this summary. It will automatically update as commits are pushed.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed everything up to 7a5ab16 in 1 minute and 38 seconds. Click for details.
  • Reviewed 211 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src-tauri/src/core/cmd.rs:350
  • Draft comment:
    The trusted_hosts parameter is now passed correctly to start_server. Consider adding a brief comment documenting the expected format and purpose of this parameter for clarity.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None
2. web-app/src/containers/TrustedHostsInput.tsx:20
  • Draft comment:
    Consider adding client-side validation (such as regex checking) to ensure that the entered trusted hosts conform to a valid host format for better UX and to prevent invalid inputs.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None

Workflow ID: wflow_7QtiPQNCclgSWTid

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@@ -38,6 +43,16 @@ export const useLocalApiServer = create<LocalApiServerState>()(
setCorsEnabled: (value) => set({ corsEnabled: value }),
verboseLogs: true,
setVerboseLogs: (value) => set({ verboseLogs: value }),
trustedHosts: [],
Copy link
Contributor

@louis-menlo louis-menlo Jun 3, 2025

Choose a reason for hiding this comment

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

Suggested change
trustedHosts: [],
trustedHosts: ["localhost", "127.0.0.1", "0.0.0.0"],

Copy link
Contributor

Choose a reason for hiding this comment

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

This also guide users on the format, otherwise add description for the comma separation.

Copy link
Contributor

@louis-menlo louis-menlo left a comment

Choose a reason for hiding this comment

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

LGTM

@david-menloai david-menloai force-pushed the fix/headers-validations-for-local-api-server branch from 7a5ab16 to c261ce1 Compare June 4, 2025 04:00
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed c261ce1 in 1 minute and 44 seconds. Click for details.
  • Reviewed 216 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. web-app/src/containers/TrustedHostsInput.tsx:19
  • Draft comment:
    Consider adding client-side validation for the host entries to ensure they match a valid hostname pattern.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None

Workflow ID: wflow_uwSAFs7SDoPaQSCn

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@david-menloai david-menloai force-pushed the fix/headers-validations-for-local-api-server branch from c261ce1 to 1ec7ab8 Compare June 4, 2025 04:15
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed 1ec7ab8 in 57 seconds. Click for details.
  • Reviewed 215 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src-tauri/src/core/cmd.rs:350
  • Draft comment:
    The trusted_hosts parameter is correctly integrated. Consider documenting the behavior when an empty list is provided.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None
2. src-tauri/src/core/server.rs:74
  • Draft comment:
    Host header validation is properly added. Consider logging a warning if header conversion fails instead of silently defaulting to an empty string.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None
3. src-tauri/src/core/server.rs:150
  • Draft comment:
    In is_valid_host, default host names are lowercased on each comparison. Precomputing the lowercased defaults could improve efficiency if the list grows.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None
4. web-app/src/containers/TrustedHostsInput.tsx:19
  • Draft comment:
    The handleBlur function splits and trims input correctly; consider adding host format validation (e.g., a simple regex) to ensure entries are well-formed.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
5. web-app/src/hooks/useLocalApiServer.ts:47
  • Draft comment:
    The addTrustedHost method appends hosts without checking for duplicates. Although the UI deduplicates on blur, adding a safeguard at the state level could prevent redundant entries.
  • Reason this comment was not posted:
    Confidence changes required: 30% <= threshold 50% None

Workflow ID: wflow_USUGFyxinO8g6dHu

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@david-menloai david-menloai force-pushed the fix/headers-validations-for-local-api-server branch from 1ec7ab8 to b674a52 Compare June 4, 2025 04:50
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed b674a52 in 49 seconds. Click for details.
  • Reviewed 214 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 6 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. src-tauri/src/core/cmd.rs:349
  • Draft comment:
    Using unwrap_or_default for app_token is acceptable if an empty token is allowed. Otherwise consider explicit error handling.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. src-tauri/src/core/server.rs:73
  • Draft comment:
    Consider logging rejected or missing Host headers for improved security auditing.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. src-tauri/src/core/server.rs:158
  • Draft comment:
    Optimize repeated to_lowercase calls by caching the lowercased host string before comparisons.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
4. web-app/src/containers/TrustedHostsInput.tsx:39
  • Draft comment:
    Consider adding a placeholder example (e.g., 'localhost, 127.0.0.1') to guide users on the expected format.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
5. src-tauri/src/core/server.rs:185
  • Draft comment:
    Ensure that trusted_hosts in ProxyConfig are consistently preprocessed (e.g., trimmed/lowercased) if needed for reliable validation.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
6. web-app/src/routes/settings/local-api-server.tsx:44
  • Draft comment:
    The trustedHosts state is now passed to the backend. Verify that the UI input format (comma-separated list) aligns with backend validation expectations.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_CGthzoD9i5CTjeEr

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@david-menloai david-menloai merged commit 30acc6f into release/v0.5.18 Jun 4, 2025
18 checks passed
@david-menloai david-menloai deleted the fix/headers-validations-for-local-api-server branch June 4, 2025 05:45
@github-project-automation github-project-automation bot moved this to QA in Jan Jun 4, 2025
@github-actions github-actions bot added this to the v0.5.19 milestone Jun 4, 2025
@david-menloai david-menloai moved this from QA to Done in Jan Jun 20, 2025
@LazyYuuki LazyYuuki removed this from the v0.7.2 milestone Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants