fix(web): prevent fetch error when hostname is an IP address in TEE check#672
fix(web): prevent fetch error when hostname is an IP address in TEE check#672lighterEB wants to merge 2 commits intonearai:mainfrom
Conversation
Summary of ChangesHello, 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 Highlights
Changelog
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
abc2d72 to
c3e1984
Compare
What does this PR do?
Fixes a bug where accessing the Web Gateway using an IP address (IPv4 or IPv6) or
localhostcausesapp.jsto crash withTypeError: Failed to construct 'Request'when parsingteeApiBase.Why is it needed?
Currently,
teeApiBase()assumes thewindow.location.hostnameis a domain name and splits it by.. When an IP address like127.0.0.1or[::1]is used, it constructs an invalid URL (e.g.,http://api.0.0.1/...) which crashes the nativefetchcall and prevents further JS execution.Changes:
localhost, since TEE attestation generally doesn't apply to bare IPs.checkTeeStatus()andfetchTeeReport()withtry...catchblocks to gracefully handle unforeseen URL parsing errors without bubbling up to the global scope.