Skip to content

[BUG] Room id with non-ASCII characters is not URL-decoded, so share links cannot join the room #253

Closed

Description

@LandmineHQ

Room id with non-ASCII characters is not URL-decoded, so share links cannot join the room

Summary

When a room is created with a non-ASCII name (e.g. 不辞), the share link becomes
https://<host>/?room=%E4%B8%8D%E8%BE%9E (browsers percent-encode non-ASCII characters when they
serialize a URL). Opening that link does not join the room: the frontend reads the raw,
still-encoded value out of the query string and sends it as the room id, while the room was created
under the decoded name.

The user is then dropped into the "create a room" form with the id field prefilled with
%E4%B8%8D%E8%BE%9E; submitting it creates a different room whose literal id is that escaped
string. Re-copying the link re-encodes the %, so the URL gets one escaping level worse on every
share (?room=%25E4%25B8%25...).

Environment

  • screego 1.12.5 (GET /config → {"version":"1.12.5","authMode":"none",...}), self-hosted
  • Windows + current Chrome/Edge (the bug is browser-agnostic: any browser that percent-encodes the
    URL will trigger it)
  • Server published through an HTTPS reverse proxy/CDN

Steps to reproduce

  1. Create a room whose id contains non-ASCII characters, e.g. 不辞 (SCREEGO_AUTH_MODE=none, no
    login required).
  2. Copy the share link (hotkey c / "copy link"). The address bar shows
    https://<host>/?room=%E4%B8%8D%E8%BE%9E.
  3. Open that link in a new tab, another browser or an incognito window.

Expected

The client joins room 不辞.

Actual

  • The join frame sent over /stream contains the escaped id:

    {"type":"join","payload":{"id":"%E4%B8%8D%E8%BE%9E"}}
  • The server closes the WebSocket with:

    room with id %E4%B8%8D%E8%BE%9E does not exist
    
  • The UI falls back to the create-room form, with the id input prefilled with %E4%B8%8D%E8%BE%9E.
    Submitting that form creates a second room whose id literally is %E4%B8%8D%E8%BE%9E.

  • Because the id is written back into the URL without encoding, an id that already contains percent
    escapes is escaped again by the browser: ?room=%E4%B8%8D%E8%BE%9E → ?room=%25E4%25B8%25....
    The copied share link is therefore broken for everybody who receives it afterwards.

Room ids that contain reserved characters (&, =, #, +, %) are affected in the same way —
the hand-rolled query parsing either truncates them or reads them partially.

Root cause

ui/src/useRoomID.ts reads and writes the query string by hand and never decodes/encodes it:

// reading (before the fix)
export const getFromURL = (key, search = window.location.search): string | undefined =>
    search
        .slice(1)
        .split('&')
        .find((param) => param.startsWith(`${key}=`))
        ?.split('=')[1]; // raw value, no decodeURIComponent

// writing (before the fix)
window.history.pushState({roomId: id}, '', id ? `?room=${id}` : '?'); // raw value, no encodeURIComponent

The value from getFromURL('room') is used directly as the room id
(useRoom.ts sends {type:'join', payload:{id: roomID}}, and RoomManage.tsx uses it as the
default value of the create form), and after the first room event the same value is written back
into the address bar with history.pushState.

The server treats the room id as an opaque string — it is the key of map[string]*Room
(ws/event_create.go, ws/event_join.go, ws/rooms.go) — so a room created as 不辞 can never be
found under %E4%B8%8D%E8%BE%9E. No server-side change is required: the client simply has to decode
exactly once when reading and encode exactly once when writing.

Suggested fix

Use the platform URL API in ui/src/useRoomID.ts so that read/write are symmetric:

export const getFromURL = (key: string, search = window.location.search): string | undefined =>
    new URLSearchParams(search).get(key) ?? undefined;

const params = new URLSearchParams();
if (id) {
    params.set('room', id);
}
const query = params.toString();
window.history.pushState({roomId: id}, '', query ? `?${query}` : '?');

This fixes non-ASCII ids (不辞), reserved characters (&, =, #, +) and ids that already
contain %, keeps old ?room=%E4%B8%8D%E8%BE%9E links working, and needs no server change.

Workaround until the fix is deployed

  • Use ASCII-only room ids, or
  • Open the link, then paste the decoded name (不辞) into the id field manually, or
  • Create the room with an ASCII id and share that link.

中文说明 For Chinese

房间名只要包含非 ASCII 字符(例如 不辞),分享链接就会被浏览器编码成
?room=%E4%B8%8D%E8%BE%9E,而前端 ui/src/useRoomID.ts 是手写解析 query、从不解码,
于是加入时把 %E4%B8%8D%E8%BE%9E 当成房间 id 发出去,服务端找不到这个id(房间是以 不辞
为 key 建的)。同时写回地址栏时也不做编码,导致 % 被二次编码,分享链接越转越坏。
修复方式是读写都改用 URLSearchParams(读=解码一次,写=编码一次),服务端无需改动。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions