本文へスキップ
ecdsa.com
WebAuthn navigator.credentials.create() / get()WebAuthn とパスキー

エラーメッセージ

SecurityError: The relying party ID is not a registrable domain suffix of, nor equal to the current domain. Subsequently, an attempt to fetch the .well-known/webauthn resource of the claimed RP ID failed.

別の表記

  • SecurityError: The relying party ID is not a registrable domain suffix of, nor equal to the current domain.

関連オリジンリクエストに対応していない Chromium のバージョンでは、文が「…nor equal to the current domain.」で終わります。ほかのブラウザーでは文言が異なり、変わらないのは DOMException の名前 `SecurityError` です。

WebAuthn navigator.credentials.create() / get() — DOMException SecurityError (Chromium)

このエラーの意味

オプションで指定した RP ID が、ページ自身のホスト名でも、その登録可能な親ドメインでもないため、ブラウザーはその RP ID での認証情報の作成も使用も拒否しました。パスキーは RP ID に紐付いています。どのページでも任意の RP ID を名乗れるとしたら、あるサイトが別のサイトのパスキーを使えてしまいます。Chromium は WebAuthn の関連オリジンリクエスト(Related Origin Requests)の仕組み、つまり `https://<rp-id>/.well-known/webauthn` を取得して RP ID がこのページのオリジンを列挙しているかを確認する方法も試しましたが、それでもリクエストは許可されませんでした。

発生する理由

修正方法

  1. 1.

    環境ごとに RP ID を設定する

    RP ID と想定するオリジンを環境ごとの設定にまとめ、開発、プレビュー、本番がそれぞれ自身のホストを使うようにしてください。また、パスキーは別の RP ID に引き継がれないことも覚えておいてください。

    js
    // Server: derive the RP ID from configuration per environment, never hard-code production.
    const rpID = process.env.WEBAUTHN_RP_ID;          // "localhost" in dev, "example.com" in production
    const expectedOrigin = process.env.WEBAUTHN_ORIGIN; // "http://localhost:3000" / "https://app.example.com"
    const options = await generateRegistrationOptions({ rpName: "Example", rpID, userName });
  2. 2.

    関連オリジンは意図的に公開する

    複数のドメインでパスキーを共有しなければならない場合は、それらのドメインを列挙した `/.well-known/webauthn` を RP ID のドメインで配信してください(現行の Chromium と Safari が対応しています)。

    json
    // https://example.com/.well-known/webauthn  (served as application/json)
    {
      "origins": ["https://example.co.uk", "https://example-shop.com"]
    }

関連するエラー

署名エラーデータベースをすべて見る