Skip to content

Commit 4c6723a

Browse files
authored
Merge pull request from GHSA-vc7j-h8xg-fv5x
* Refuse to accept foreign users in OpenID responses * Make sure we correctly handle server names with colons in them --------- Co-authored-by: Tadeusz Sośnierz <tadeusz@sosnierz.com>
1 parent cfc6358 commit 4c6723a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/provisioning/api.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,16 @@ export class ProvisioningApi {
388388
throw new ApiError("Server did not respond with the correct sub information", ErrCode.BadOpenID);
389389
}
390390
const userId = response.data.sub;
391+
392+
const mxidMatch = userId.match(/([^:]+):(.+)/);
393+
if (!mxidMatch) {
394+
throw new ApiError("Server did not respond with a valid MXID", ErrCode.BadOpenID);
395+
}
396+
const [, _localpart, serverName] = mxidMatch;
397+
if (serverName !== server) {
398+
throw new ApiError("Server returned a MXID belonging to another homeserver", ErrCode.BadOpenID);
399+
}
400+
391401
const token = this.widgetTokenPrefix + uuid().replace(/-/g, "");
392402
const expiresTs = Date.now() + this.widgetTokenLifetimeMs;
393403
await this.store.createSession({

0 commit comments

Comments
 (0)