From 04102c5096a153adb01b51915df0129bac4bf913 Mon Sep 17 00:00:00 2001 From: xela92 Date: Tue, 24 Nov 2026 15:21:54 +0100 Subject: [PATCH] Handle literal concatenation in DWService login configuration --- internal/auth/loginpage.go | 14 +++++++++-- internal/auth/loginpage_concat_test.go | 32 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 internal/auth/loginpage_concat_test.go diff --git a/internal/auth/loginpage.go b/internal/auth/loginpage.go index fcdb337..188c9e2 100644 --- a/internal/auth/loginpage.go +++ b/internal/auth/loginpage.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "regexp" + "strings" ) // LoginPageURL is the entry point served by DWService. @@ -32,7 +33,8 @@ func (c *LoginConfig) AuthURL() string { // hexBlobRe matches the hex-encoded config blob passed to dwsInitDecodeHex() in // loadConfiguration(); it decodes to the JSON that seeds dwsConfig. -var hexBlobRe = regexp.MustCompile(`dwsInitDecodeHex\('([0-9a-f]{200,})'\)`) +var hexBlobRe = regexp.MustCompile(`dwsInitDecodeHex\(\s*((?:'[0-9a-f]+'|"[0-9a-f]+")(?:\s*\+\s*(?:'[0-9a-f]+'|"[0-9a-f]+"))*)\s*\)`) +var hexPartRe = regexp.MustCompile(`['"]([0-9a-f]+)['"]`) type rawLoginConfig struct { BaseURL string `json:"baseUrl"` @@ -67,7 +69,15 @@ func parseLoginConfig(html []byte) (*LoginConfig, error) { if m == nil { return nil, fmt.Errorf("login config blob not found on page") } - raw, err := hex.DecodeString(string(m[1])) + // Accept only literal hex strings joined with '+', never evaluate JavaScript. + var encoded strings.Builder + for _, part := range hexPartRe.FindAllSubmatch(m[1], -1) { + encoded.Write(part[1]) + } + if encoded.Len() < 200 { + return nil, fmt.Errorf("login config blob too short") + } + raw, err := hex.DecodeString(encoded.String()) if err != nil { return nil, fmt.Errorf("decode config hex: %w", err) } diff --git a/internal/auth/loginpage_concat_test.go b/internal/auth/loginpage_concat_test.go new file mode 100644 index 0000000..355b675 --- /dev/null +++ b/internal/auth/loginpage_concat_test.go @@ -0,0 +1,32 @@ +package auth + +import ( + "encoding/hex" + "strings" + "testing" +) + +func TestLoginConfigLiteralConcatenation(t *testing.T) { + raw := `{"baseUrl":"https://access.dwservice.net/","requestUrl":"https://access.dwservice.net/","cryptAlgorithmAccept":[{"importKey":{"keyData":"synthetic-server-public-key"}}]}` + encoded := hex.EncodeToString([]byte(raw)) + mid := len(encoded) / 2 + for _, expr := range []string{ + "'" + encoded + "'", + "'" + encoded[:mid] + "'+'" + encoded[mid:] + "'", + "\"" + encoded[:mid] + "\" + \n \"" + encoded[mid:] + "\"", + } { + cfg, err := parseLoginConfig([]byte("loadConfiguration(dwsInitDecodeHex(" + expr + "))")) + if err != nil || cfg.BaseURL != "https://access.dwservice.net/" || cfg.ServerKeyB64 != "synthetic-server-public-key" { + t.Fatal("literal config not decoded correctly") + } + } + for _, expr := range []string{ + "'" + encoded[:mid] + "'+callFunction()+'" + encoded[mid:] + "'", + "'" + encoded[:mid] + "'+window.value", + "'" + strings.Repeat("g", 300) + "'", + } { + if _, err := parseLoginConfig([]byte("dwsInitDecodeHex(" + expr + ")")); err == nil { + t.Fatal("nonliteral config accepted") + } + } +}