mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridgev2/commands: url-decode cookie parameters
This commit is contained in:
parent
741b4e823f
commit
1b7a78b811
1 changed files with 31 additions and 2 deletions
|
|
@ -12,6 +12,7 @@ import (
|
|||
"fmt"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/skip2/go-qrcode"
|
||||
|
|
@ -120,11 +121,12 @@ func checkLoginCommandDirectParams(ce *Event, login bridgev2.LoginProcess, nextS
|
|||
}
|
||||
input := make(map[string]string)
|
||||
for i, param := range nextStep.CookiesParams.Fields {
|
||||
if match, _ := regexp.MatchString(param.Pattern, ce.Args[i]); !match {
|
||||
val := maybeURLDecodeCookie(ce.Args[i], ¶m)
|
||||
if match, _ := regexp.MatchString(param.Pattern, val); !match {
|
||||
ce.Reply("Invalid value for %s: doesn't match regex `%s`", param.ID, param.Pattern)
|
||||
return nil
|
||||
}
|
||||
input[param.ID] = ce.Args[i]
|
||||
input[param.ID] = val
|
||||
}
|
||||
nextStep, err = login.(bridgev2.LoginProcessCookies).SubmitCookies(ce.Ctx, input)
|
||||
}
|
||||
|
|
@ -349,6 +351,12 @@ func (clcs *cookieLoginCommandState) submit(ce *Event) {
|
|||
ce.Reply("Failed to parse input as JSON: %v", err)
|
||||
return
|
||||
}
|
||||
for _, field := range clcs.Data.Fields {
|
||||
val, ok := cookiesInput[field.ID]
|
||||
if ok {
|
||||
cookiesInput[field.ID] = maybeURLDecodeCookie(val, &field)
|
||||
}
|
||||
}
|
||||
}
|
||||
var missingKeys []string
|
||||
for _, field := range clcs.Data.Fields {
|
||||
|
|
@ -374,6 +382,27 @@ func (clcs *cookieLoginCommandState) submit(ce *Event) {
|
|||
doLoginStep(ce, clcs.Login, nextStep)
|
||||
}
|
||||
|
||||
func maybeURLDecodeCookie(val string, field *bridgev2.LoginCookieField) string {
|
||||
if val == "" {
|
||||
return val
|
||||
}
|
||||
isCookie := slices.ContainsFunc(field.Sources, func(src bridgev2.LoginCookieFieldSource) bool {
|
||||
return src.Type == bridgev2.LoginCookieTypeCookie
|
||||
})
|
||||
if !isCookie {
|
||||
return val
|
||||
}
|
||||
match, _ := regexp.MatchString(field.Pattern, val)
|
||||
if !match {
|
||||
return val
|
||||
}
|
||||
decoded, err := url.QueryUnescape(val)
|
||||
if err != nil {
|
||||
return val
|
||||
}
|
||||
return decoded
|
||||
}
|
||||
|
||||
func doLoginStep(ce *Event, login bridgev2.LoginProcess, step *bridgev2.LoginStep) {
|
||||
if step.Instructions != "" {
|
||||
ce.Reply(step.Instructions)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue