Skip to content

Commit 9b8e77e

Browse files
fix(tunnel): accept ?token= query param on /.tunnel for browser WS auth (JavaScriptSolidServer#528) (JavaScriptSolidServer#529)
1 parent ad289f9 commit 9b8e77e

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/tunnel/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ export async function tunnelPlugin(fastify, options = {}) {
5757
fastify.get(wsPath, { websocket: true }, async (connection, request) => {
5858
const socket = connection.socket;
5959

60+
// Browser WebSockets can't set an Authorization header, so accept the
61+
// bearer token as a ?token= query param too — mirrors the /.webrtc
62+
// endpoint. Lets browser-based tunnel clients authenticate. (#528)
63+
const queryToken = request.query?.token;
64+
if (queryToken && !request.headers.authorization) {
65+
request.headers.authorization = `Bearer ${queryToken}`;
66+
}
67+
6068
// Authenticate
6169
const { webId } = await getWebIdFromRequestAsync(request);
6270
if (!webId) {

0 commit comments

Comments
 (0)