This commit is contained in:
shwoop 2025-09-18 16:37:34 +02:00
parent 7ce73c5490
commit bc95aa561e
No known key found for this signature in database
GPG key ID: 95A35B68C1E5F95A
4 changed files with 7 additions and 7 deletions

View file

@ -39,7 +39,6 @@ var wantsMsg = ` wants you to sign in with your Ethereum account:\n`
var address = `(0x[a-fA-F0-9]{40})\n` var address = `(0x[a-fA-F0-9]{40})\n`
// Optional statement (any line not containing "\n\n") // Optional statement (any line not containing "\n\n")
// var statement = `(?:[^\n]+\n)?`
var statement = `(?:.*\n)?` var statement = `(?:.*\n)?`
// URI // URI
@ -77,13 +76,15 @@ var siweMessageRegex = regexp.MustCompile(`(?m)^` + scheme + domain + wantsMsg +
var ErrMalformedSIWEMessage = errors.New("the message is asking to sign in with Ethereum but does not conform to EIP-4361") var ErrMalformedSIWEMessage = errors.New("the message is asking to sign in with Ethereum but does not conform to EIP-4361")
const suggestiveLanguage = "wants you to sign in with your Ethereum account"
func validateSIWE(req *SignDataRequest) error { func validateSIWE(req *SignDataRequest) error {
for _, message := range req.Messages { for _, message := range req.Messages {
s, ok := message.Value.(string) s, ok := message.Value.(string)
if !ok { if !ok {
continue continue
} }
if !strings.Contains(s, "wants you to sign in with your Ethereum account") { if !strings.Contains(s, suggestiveLanguage) {
continue continue
} }

View file

@ -24,4 +24,4 @@
}, },
"error_msg_pattern": "sign in request address \\(0x1234567890123456789012345678901234567890\\) does not match source: 0x.*" "error_msg_pattern": "sign in request address \\(0x1234567890123456789012345678901234567890\\) does not match source: 0x.*"
} }
} }

View file

@ -92,7 +92,7 @@
}, },
"domain is RFC 3986 authority with userinfo and port": { "domain is RFC 3986 authority with userinfo and port": {
"msg": "test@127.0.0.1:8080 wants you to sign in with your Ethereum account:\n{{Account}}\n\nI accept the ServiceOrg Terms of Service: https://service.org/tos\n\nURI: https://service.org/login\nVersion: 1\nChain ID: 1\nNonce: 32891757\nIssued At: 2021-09-30T16:25:24.000Z", "msg": "test@127.0.0.1:8080 wants you to sign in with your Ethereum account:\n{{Account}}\n\nI accept the ServiceOrg Terms of Service: https://service.org/tos\n\nURI: https://service.org/login\nVersion: 1\nChain ID: 1\nNonce: 32891757\nIssued At: 2021-09-30T16:25:24.000Z",
"request_context":{ "request_context": {
"transport": "https", "transport": "https",
"source": "test@127.0.0.1:8080" "source": "test@127.0.0.1:8080"
} }
@ -105,7 +105,7 @@
"request_context": { "request_context": {
"transport": "https", "transport": "https",
"source": "[::cafe]" "source": "[::cafe]"
} }
}, },
"uri ipv6": { "uri ipv6": {
"msg": "service.org wants you to sign in with your Ethereum account:\n{{Account}}\n\n\nURI: https://[::cafe]\nVersion: 1\nChain ID: 1\nNonce: 32891757\nIssued At: 2021-09-30T16:25:24.000Z" "msg": "service.org wants you to sign in with your Ethereum account:\n{{Account}}\n\n\nURI: https://[::cafe]\nVersion: 1\nChain ID: 1\nNonce: 32891757\nIssued At: 2021-09-30T16:25:24.000Z"

View file

@ -32,5 +32,4 @@
"No scheme - ://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body": "service.org wants you to sign in with your Ethereum account:\n0x{{Account}}\n\n\nURI: ://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body\nVersion: 1\nChain ID: 1\nNonce: 32891757\nIssued At: 2021-09-30T16:25:24.000Z", "No scheme - ://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body": "service.org wants you to sign in with your Ethereum account:\n0x{{Account}}\n\n\nURI: ://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body\nVersion: 1\nChain ID: 1\nNonce: 32891757\nIssued At: 2021-09-30T16:25:24.000Z",
"bad query - uri://user:pass@example.com:123/one/two.three ?q1=a1&q2=a2#body": "service.org wants you to sign in with your Ethereum account:\n0x{{Account}}\n\n\nURI: uri://user:pass@example.com:123/one/two.three ?q1=a1&q2=a2#body\nVersion: 1\nChain ID: 1\nNonce: 32891757\nIssued At: 2021-09-30T16:25:24.000Z", "bad query - uri://user:pass@example.com:123/one/two.three ?q1=a1&q2=a2#body": "service.org wants you to sign in with your Ethereum account:\n0x{{Account}}\n\n\nURI: uri://user:pass@example.com:123/one/two.three ?q1=a1&q2=a2#body\nVersion: 1\nChain ID: 1\nNonce: 32891757\nIssued At: 2021-09-30T16:25:24.000Z",
"bad fragment - uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2 #body": "service.org wants you to sign in with your Ethereum account:\n0x{{Account}}\n\n\nURI: uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2 #body\nVersion: 1\nChain ID: 1\nNonce: 32891757\nIssued At: 2021-09-30T16:25:24.000Z" "bad fragment - uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2 #body": "service.org wants you to sign in with your Ethereum account:\n0x{{Account}}\n\n\nURI: uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2 #body\nVersion: 1\nChain ID: 1\nNonce: 32891757\nIssued At: 2021-09-30T16:25:24.000Z"
}
}