Skip to content

fix(web): prevent fetch error when hostname is an IP address in TEE check#672

Open
lighterEB wants to merge 2 commits intonearai:mainfrom
lighterEB:fix/web-gateway-tee-api-base
Open

fix(web): prevent fetch error when hostname is an IP address in TEE check#672
lighterEB wants to merge 2 commits intonearai:mainfrom
lighterEB:fix/web-gateway-tee-api-base

Conversation

@lighterEB
Copy link

What does this PR do?
Fixes a bug where accessing the Web Gateway using an IP address (IPv4 or IPv6) or localhost causes app.js to crash with TypeError: Failed to construct 'Request' when parsing teeApiBase.

Why is it needed?
Currently, teeApiBase() assumes the window.location.hostname is a domain name and splits it by .. When an IP address like 127.0.0.1 or [::1] is used, it constructs an invalid URL (e.g., http://api.0.0.1/...) which crashes the native fetch call and prevents further JS execution.

Changes:

  • Skips TEE checks if the hostname is an IP address or localhost, since TEE attestation generally doesn't apply to bare IPs.
  • Wraps checkTeeStatus() and fetchTeeReport() with try...catch blocks to gracefully handle unforeseen URL parsing errors without bubbling up to the global scope.

@github-actions github-actions bot added the scope: channel/web Web gateway channel label Mar 7, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the Web Gateway where the application would crash when accessed via an IP address or localhost. The issue stemmed from the teeApiBase function incorrectly attempting to parse IP addresses as domain names, leading to invalid URL construction and TypeError exceptions during fetch calls. The changes introduce robust hostname validation to bypass TEE checks for non-domain hostnames and enhance error handling for TEE-related network requests, significantly improving the application's stability and user experience in diverse network environments.

Highlights

  • TEE Check Logic: Implemented logic in teeApiBase to identify and skip TEE attestation checks when the hostname is an IP address (IPv4 or IPv6) or localhost, as TEE attestation is not applicable in these scenarios.
  • Error Handling: Added try...catch blocks around the fetch calls within checkTeeStatus and fetchTeeReport to gracefully handle potential URL parsing errors and prevent application crashes.
Changelog
  • src/channels/web/static/app.js
    • Modified teeApiBase to detect and return null for IP addresses and localhost hostnames.
    • Encapsulated fetch calls in checkTeeStatus and fetchTeeReport within try...catch blocks for error resilience.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions bot added size: S 10-49 changed lines risk: medium Business logic, config, or moderate-risk modules contributor: new First-time contributor labels Mar 7, 2026
Copy link
Contributor

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

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 effectively addresses a crash that occurs when the web gateway is accessed via an IP address instead of a hostname. The approach of skipping TEE checks for IP addresses and localhost is sound. The addition of a try...catch block around the fetch call in checkTeeStatus adds robustness. I've provided a couple of suggestions to further improve the code: one to make the IPv4 address detection more precise, and another to add logging to an empty error handler to aid in future debugging. Additionally, I noticed the PR description mentions wrapping fetchTeeReport in a try...catch as well, but that change doesn't appear in this PR; it would be good to include that for consistency.

…heck

Currently, teeApiBase() splits the hostname by '.' and incorrectly parses IP addresses like 127.0.0.1 or localhost into invalid URLs (e.g., http://api.0.0.1/), which causes the fetch API to throw a 'Failed to construct Request' TypeError and crashes the web UI.

This fix:
- Skips TEE checks if the hostname is an IP address or localhost.
- Wraps checkTeeStatus() and fetchTeeReport() with try...catch to gracefully handle any unforeseen fetch errors without bubbling up to the global scope.
@lighterEB lighterEB force-pushed the fix/web-gateway-tee-api-base branch from abc2d72 to c3e1984 Compare March 7, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: new First-time contributor risk: medium Business logic, config, or moderate-risk modules scope: channel/web Web gateway channel size: S 10-49 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant