chore: update host validation error to 403#2306
Conversation
Summary of ChangesHello @Yuan325, 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 updates the HTTP status code returned when a request is received with an invalid host header. Previously, a Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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 correctly updates the host validation error code from 400 to 403, which is more semantically appropriate for this type of authorization failure. The change is consistent with the linked MCP update. I have added one comment regarding a potential improvement to make the host validation logic more robust by correctly handling port numbers in the Host header.
Update error code from 400 to 403 according to MCP [updates](modelcontextprotocol/modelcontextprotocol#1439) for invalid origin header. Also updated hostCheck to only check host, not port. To test, run Toolbox with the following (also work with port number e.g. `--allowed-host=127.0.0.1:5000`): ``` go run . --allowed-hosts=127.0.0.1 ``` Test with the following: ``` // curl successfully curl -H "Host: 127.0.0.1:5000" http://127.0.0.1:5000 // curl successfully curl -H "Host: 127.0.0.1:3000" http://127.0.0.1:5000 // will show Invalid Host Header error curl -H "Host: attacker:5000" http://127.0.0.1:5000 ``` d00b6fd
Update error code from 400 to 403 according to MCP [updates](modelcontextprotocol/modelcontextprotocol#1439) for invalid origin header. Also updated hostCheck to only check host, not port. To test, run Toolbox with the following (also work with port number e.g. `--allowed-host=127.0.0.1:5000`): ``` go run . --allowed-hosts=127.0.0.1 ``` Test with the following: ``` // curl successfully curl -H "Host: 127.0.0.1:5000" http://127.0.0.1:5000 // curl successfully curl -H "Host: 127.0.0.1:3000" http://127.0.0.1:5000 // will show Invalid Host Header error curl -H "Host: attacker:5000" http://127.0.0.1:5000 ``` d00b6fd
Update error code from 400 to 403 according to MCP [updates](modelcontextprotocol/modelcontextprotocol#1439) for invalid origin header. Also updated hostCheck to only check host, not port. To test, run Toolbox with the following (also work with port number e.g. `--allowed-host=127.0.0.1:5000`): ``` go run . --allowed-hosts=127.0.0.1 ``` Test with the following: ``` // curl successfully curl -H "Host: 127.0.0.1:5000" http://127.0.0.1:5000 // curl successfully curl -H "Host: 127.0.0.1:3000" http://127.0.0.1:5000 // will show Invalid Host Header error curl -H "Host: attacker:5000" http://127.0.0.1:5000 ``` d00b6fd
Update error code from 400 to 403 according to MCP [updates](modelcontextprotocol/modelcontextprotocol#1439) for invalid origin header. Also updated hostCheck to only check host, not port. To test, run Toolbox with the following (also work with port number e.g. `--allowed-host=127.0.0.1:5000`): ``` go run . --allowed-hosts=127.0.0.1 ``` Test with the following: ``` // curl successfully curl -H "Host: 127.0.0.1:5000" http://127.0.0.1:5000 // curl successfully curl -H "Host: 127.0.0.1:3000" http://127.0.0.1:5000 // will show Invalid Host Header error curl -H "Host: attacker:5000" http://127.0.0.1:5000 ```
Update error code from 400 to 403 according to MCP [updates](modelcontextprotocol/modelcontextprotocol#1439) for invalid origin header. Also updated hostCheck to only check host, not port. To test, run Toolbox with the following (also work with port number e.g. `--allowed-host=127.0.0.1:5000`): ``` go run . --allowed-hosts=127.0.0.1 ``` Test with the following: ``` // curl successfully curl -H "Host: 127.0.0.1:5000" http://127.0.0.1:5000 // curl successfully curl -H "Host: 127.0.0.1:3000" http://127.0.0.1:5000 // will show Invalid Host Header error curl -H "Host: attacker:5000" http://127.0.0.1:5000 ```
Update error code from 400 to 403 according to MCP updates for invalid origin header.
Also updated hostCheck to only check host, not port.
To test, run Toolbox with the following (also work with port number e.g.
--allowed-host=127.0.0.1:5000):Test with the following: