Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions packages/vscode-ide-companion/src/ide-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,6 @@ export class IDEServer {
}),
);

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.

critical

Removing the host header check introduces a critical security vulnerability. By binding the server to 0.0.0.0, it becomes accessible from the local network. Without the host check, any device on the network can send requests to it. Although most requests require an auth token, initialize requests are unauthenticated for backward compatibility. This could allow an attacker on the same network to trigger actions in the IDE, such as opening a diff view with malicious content (openDiff tool), which poses a security risk.

I suggest re-introducing a host check that is flexible enough for the Docker use case. Checking just the hostname part of the Host header against a list of allowed hostnames like localhost and 127.0.0.1 would be much safer and should still work with Docker port forwarding.

      app.use((req, res, next) => {
        const hostname = (req.headers.host || '').split(':')[0];
        const allowedHostnames = [
          'localhost',
          '127.0.0.1',
        ];
        if (!allowedHostnames.includes(hostname)) {
          return res.status(403).json({ error: 'Invalid Host header' });
        }
        next();
      });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes it is correct but we are in a conflict here between header sec and sandbox env.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @chrstnb
who is responsible here ? I dont get any update since weeks

Damian

app.use((req, res, next) => {
const host = req.headers.host || '';
const allowedHosts = [
`localhost:${this.port}`,
`127.0.0.1:${this.port}`,
];
if (!allowedHosts.includes(host)) {
return res.status(403).json({ error: 'Invalid Host header' });
}
next();
});

app.use((req, res, next) => {
const authHeader = req.headers.authorization;
if (!authHeader) {
Expand Down Expand Up @@ -331,7 +319,7 @@ export class IDEServer {
}
});

this.server = app.listen(0, '127.0.0.1', async () => {
this.server = app.listen(0, '0.0.0.0', async () => {
const address = (this.server as HTTPServer).address();
if (address && typeof address !== 'string') {
this.port = address.port;
Expand All @@ -343,7 +331,7 @@ export class IDEServer {
os.tmpdir(),
`gemini-ide-server-${process.ppid}.json`,
);
this.log(`IDE server listening on http://127.0.0.1:${this.port}`);
this.log(`IDE server listening on http://0.0.0.0:${this.port}`);

if (this.authToken) {
await writePortAndWorkspace({
Expand Down