Skip to content

✨ [desktop,core]: Add hostname to User-Agent for device identification#94

Open
yuler wants to merge 3 commits into
mainfrom
desktop-agent-with-hostname
Open

✨ [desktop,core]: Add hostname to User-Agent for device identification#94
yuler wants to merge 3 commits into
mainfrom
desktop-agent-with-hostname

Conversation

@yuler

@yuler yuler commented May 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add hostname crate to Rust backend and expose get_hostname Tauri command
  • Include system hostname in User-Agent header for device identification during authorization
  • Update Session model to parse and display hostname in session summaries

Test plan

  • Session model tests pass with new hostname parsing
  • Verify hostname appears in User-Agent on macOS/Windows/Linux
  • Verify device authorization page shows device name

Include system hostname in the User-Agent header so devices can be identified during authorization. Update Session model to parse and display hostname in session summaries.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the collection and display of the local hostname in the desktop application's user agent. It adds a Rust command to retrieve the hostname, includes it in the user agent string generated in the frontend, and parses it in the backend to display in the session summary. The review feedback highlights three key areas for improvement: a regression in the backend user agent formatting when the client is missing, a potential frontend failure where a rejected hostname promise could discard successfully retrieved system info, and a robustness concern regarding non-ASCII or control characters in hostnames that could break HTTP headers.

Comment thread core/app/models/session.rb
Comment thread apps/desktop/src/api.ts
Comment thread apps/desktop/src-tauri/src/lib.rs
- Fix user agent summary regression when client is not present
- Handle get_hostname promise rejection individually
- Sanitize hostname to safe ASCII characters
@yuler

yuler commented May 27, 2026

Copy link
Copy Markdown
Owner Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds the system hostname to the desktop application's User-Agent string and updates the backend session model to parse and display it. The feedback focuses on standardizing the User-Agent format by enclosing the hostname within the comment parentheses (e.g., (platform; hostname)) rather than appending it to the end. This includes suggestions to sanitize parentheses from the hostname in Rust, adjust the User-Agent construction in TypeScript, update the parsing regex and exclude "Unknown" hostnames in Ruby, and align the test cases accordingly.

Comment thread apps/desktop/src-tauri/src/lib.rs
Comment thread apps/desktop/src/api.ts Outdated
Comment thread core/app/models/session.rb Outdated
Comment thread core/test/models/session_test.rb
- Filter parentheses from hostname in Rust
- Include hostname in comment parentheses (platform; hostname)
- Update regex to parse new format, skip Unknown hostname
- Update test to match new format
@yuler

yuler commented May 27, 2026

Copy link
Copy Markdown
Owner Author

/
/gemini review

@yuler yuler changed the title ✨ [desktop]: Add hostname to User-Agent for device identification ✨ [desktop,core]: Add hostname to User-Agent for device identification May 27, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds the system hostname to the desktop app's User-Agent string and updates the Rails backend to parse and display it in the session summary. The changes include adding a new get_hostname Tauri command in Rust, updating the frontend API to fetch and append the hostname, and modifying the Session model and its tests in Ruby. The reviewer feedback suggests filtering out backslashes from the hostname in Rust to prevent malformed User-Agent headers, and using a case-insensitive comparison for the "Unknown" fallback string in Ruby.

let sanitized: String = h
.to_string_lossy()
.chars()
.filter(|c| c.is_ascii() && !c.is_control() && *c != '(' && *c != ')')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The backslash character is a special character in User-Agent comments (used as an escape character). If a hostname contains a backslash, it can escape the closing parenthesis or other characters, leading to malformed User-Agent headers and potential parsing issues on the server. We should filter out backslashes along with ( and ) to ensure the hostname is safe for the User-Agent comment block.

Suggested change
.filter(|c| c.is_ascii() && !c.is_control() && *c != '(' && *c != ')')
.filter(|c| c.is_ascii() && !c.is_control() && *c != '(' && *c != ')' && *c != '\\')

user_agent.truncate(35)
parts << (client || os)
end
parts << "(#{hostname})" if hostname.present? && hostname != "Unknown"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To make the check more robust against different casing of the "Unknown" fallback (e.g., if a client or future version sends "unknown" or "UNKNOWN"), we should perform a case-insensitive comparison using casecmp?.

    parts << "(#{hostname})" if hostname.present? && !hostname.casecmp?("unknown")

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant