1

I am trying to implement SIWS using the instructions from https://github.com/phantom/sign-in-with-solana, so far it works.

But its pretty vague, how the nonce is used, in the example the nonce is even hardcoded with a fixed value (which seems quite insecure). The documentation just says to include in a nonce in the signInData.

However looking at the code in import { verifySignIn } from "@solana/wallet-standard-util"; it looks it is just checking that the user signed the message. It does not look like it is doing anything with the nonce (other than the nonce being part of the message).

I don't see how including a nonce does anything to prevent replay attacks though? There is no indication in the docs requiring the user to implement the nonce encryption/decryption on the server side similar like this https://en.wikipedia.org/wiki/Cryptographic_nonce.

Am I right in saying that we need to implement this on our own?

From the reference implementation

import type {
  SolanaSignInInput,
  SolanaSignInOutput,
} from "@solana/wallet-standard-features";
import { verifySignIn } from "@solana/wallet-standard-util";

export function verifySIWS(
  input: SolanaSignInInput,
  output: SolanaSignInOutput
): boolean {
  const serialisedOutput: SolanaSignInOutput = {
    account: {
      publicKey: new Uint8Array(output.account.publicKey),
      ...output.account
    },
    signature: new Uint8Array(output.signature),
    signedMessage: new Uint8Array(output.signedMessage),
  };
  return verifySignIn(input, serialisedOutput);
}

It then says to call the backend verifySIWS

// Verify the sign-in output against the generated input server-side
  let strPayload = JSON.stringify({ input, output });
  const verifyResponse = await fetch("/backend/verifySIWS", {
    method: "POST",
    body: strPayload,
  });
  const success = await verifyResponse.json();

However, cant the attacker just replay this entire post request which has the input & output with the nonce included in both message ?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.