Skip to content

Commit

Permalink
Require non-empty user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Apr 10, 2024
1 parent 714c86e commit 2e53f8b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions doc/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,7 @@ Multiple set messages may be sent in one message where each message is separated
4005 Closed to protect your security
When the client does something that compromises its security and the server closes the connection to force the client to fix its code.
4006 Identify yourself
When the client is not providing sufficient information in the User-Agent header.
```
7 changes: 7 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ wss.on('connection', (ws, req) => {
return;
}

if (!req.headers['user-agent']) {
logger.info('A connection was closed for lacking a valid user-agent.');
ws.send('Please provide a valid User-Agent header as required by https://docs.turbowarp.org/cloud-variables#advanced. If you use a cloud variable library, contact the author to find out how to do that.');
ws.close(4006);
return;
}

const client = new Client(ws, req);

let isHandshaking = false;
Expand Down

0 comments on commit 2e53f8b

Please sign in to comment.