Skip to content

Commit 089e0f2

Browse files
authored
Merge pull request #15 from oasisprotocol/ptrus/feature/siwe-statement-validation
auth/siwe: validate statement
2 parents 920be02 + dc089f3 commit 089e0f2

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

api/auth/jwt.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const (
2929

3030
nonceTTL = 60 * time.Second
3131
jwtTTL = 30 * time.Minute
32+
33+
siweStatement = "Sign in to ROFL App Backend"
3234
)
3335

3436
// CustomClaims are the claims for the JWT.
@@ -189,6 +191,17 @@ func SIWELoginHandler(redisClient *redis.Client, cfg *config.AuthConfig) func(w
189191
common.WriteError(w, http.StatusUnauthorized, "invalid SIWE signature")
190192
return
191193
}
194+
// Verify the statement.
195+
statement := msg.GetStatement()
196+
if statement == nil {
197+
common.WriteError(w, http.StatusUnauthorized, "missing statement")
198+
return
199+
}
200+
if *statement != siweStatement {
201+
common.WriteError(w, http.StatusUnauthorized, "invalid statement")
202+
return
203+
}
204+
192205
// Verify the Chain ID if set.
193206
if cfg.SIWEChainID != 0 && msg.GetChainID() != cfg.SIWEChainID {
194207
common.WriteError(w, http.StatusUnauthorized, "invalid SIWE chain ID")

e2e/e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func doSIWELogin(t *testing.T, client *http.Client) string {
168168
msg, err := siwe.InitMessage(siweDomain, addr.Hex(), "http://"+siweDomain, nonceRes.Nonce, map[string]interface{}{
169169
"chainId": 1,
170170
"version": "1",
171-
"statement": "Sign in to localhost",
171+
"statement": "Sign in to ROFL App Backend",
172172
})
173173
require.NoError(err, "failed to build SIWE message")
174174
msgHash := signHash([]byte(msg.String()))

frontend_test/src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ loginBtn.onclick = async () => {
2525
const siweMsg = new SiweMessage({
2626
domain: "localhost",
2727
address: checksummed,
28-
statement: "Sign in to localhost",
28+
statement: "Sign in to ROFL App Backend",
2929
uri: "http://" + domain,
3030
version: "1",
3131
chainId: 1,

0 commit comments

Comments
 (0)