Validate mxid format in web login

This commit is contained in:
Cadence Ember
2025-02-18 15:59:32 +13:00
parent ea7aec5e66
commit 902dfa7e7c
3 changed files with 20 additions and 2 deletions

View File

@@ -11,6 +11,6 @@ block body
input(type="hidden" name="next" value=next)
.d-flex.gy4.fd-column
label.s-label(for="mxid") Your Matrix ID
input.fl-grow1.s-input.wmx3#mxid(name="mxid" required placeholder="@user:example.org")
input.fl-grow1.s-input.wmx3#mxid(name="mxid" required placeholder="@user:example.org" pattern="@([^:]+):([a-z0-9:\-]+\.[a-z0-9.:\-]+)")
div
button.s-btn.s-btn__github#log-in-button Continue with Matrix

View File

@@ -17,7 +17,7 @@ const auth = sync.require("../auth")
const schema = {
form: z.object({
mxid: z.string(),
mxid: z.string().regex(/^@([^:]+):([a-z0-9:-]+\.[a-z0-9.:-]+)$/),
next: z.string().optional()
}),
token: z.object({

View File

@@ -16,6 +16,24 @@ test("log in with matrix: shows web page with form on first request", async t =>
let token
test("log in with matrix: checks if mxid format looks valid", async t => {
const [error] = await tryToCatch(() => router.test("post", "/api/log-in-with-matrix", {
body: {
mxid: "x@cadence:cadence.moe"
}
}))
t.equal(error.data.issues[0].validation, "regex")
})
test("log in with matrix: checks if mxid domain format looks valid", async t => {
const [error] = await tryToCatch(() => router.test("post", "/api/log-in-with-matrix", {
body: {
mxid: "@cadence:cadence."
}
}))
t.equal(error.data.issues[0].validation, "regex")
})
test("log in with matrix: sends message when there is no m.direct data", async t => {
const event = {}
let called = 0