Skip to content

chore: update host validation error to 403#2306

Merged
Yuan325 merged 2 commits into
mainfrom
host-error
Jan 15, 2026
Merged

chore: update host validation error to 403#2306
Yuan325 merged 2 commits into
mainfrom
host-error

Conversation

@Yuan325

@Yuan325 Yuan325 commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

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):

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

@Yuan325 Yuan325 requested a review from a team January 13, 2026 22:59
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 400 Bad Request was issued, but this has been changed to 403 Forbidden to better reflect the nature of the access denial and to comply with external protocol specifications. This ensures a more precise and standardized error handling for host validation failures.

Highlights

  • Error Code Update: The HTTP status code returned for invalid host headers has been updated from 400 Bad Request to 403 Forbidden.
  • Protocol Alignment: This change aligns the error response with updates specified in the Model Context Protocol (MCP).

🧠 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 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.

@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 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.

Comment thread internal/server/server.go Outdated
@Yuan325 Yuan325 enabled auto-merge (squash) January 15, 2026 20:46
@Yuan325 Yuan325 merged commit d00b6fd into main Jan 15, 2026
12 checks passed
@Yuan325 Yuan325 deleted the host-error branch January 15, 2026 21:09
github-actions Bot pushed a commit to Genesis929/genai-toolbox that referenced this pull request Jan 15, 2026
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
github-actions Bot pushed a commit to CrazyForks/genai-toolbox that referenced this pull request Jan 15, 2026
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
github-actions Bot pushed a commit to Jaleel-zhu/genai-toolbox that referenced this pull request Jan 15, 2026
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
mahlevanshika pushed a commit to mahlevanshika/genai-toolbox that referenced this pull request Jan 22, 2026
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
```
kshalu-code pushed a commit to kshalu-code/genai-toolbox that referenced this pull request Feb 4, 2026
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
```
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.

3 participants