/tmp/

雑なメモを置く場所。書いた内容の責任は取らないし、正確性、永続性なども保証しない。

Credential Management Level 1

Credential Management

Credential Management Level 1

  • Web サイトが UA に資格情報をリクエストし、UA がそれを使用できるようにする API
  • スキームがダウングレードする場合はクレデンシャルを共有してはいけない(MUST NOT)
  • 呼び出された Origin と Credential の Origin を比較して決定される
    • admin.example.com に保存されているクレデンシャルを www.example.com から呼び出すことは可能
    • XSS でパスワード抜かれることに繋がりそう
  • CSP で保護することが推奨されている
  • Secure Context のみで利用可能
  • Timing Attack 防止のため、回数に制限もかける (SHOULD)
<html>
  <body>
    <form action="/login.php" method="post" id="login">
      <input name="username" />
      <input type="password" name="password" />
      <button type="submit">Login</button>
    </form>

    <button onclick="autoLogin()">Auto Login</button>
  <script>
    function autoLogin() {
      // navigator.credentials.get({ 'password': true }).then(credential => { if (credential) { console.log(credential); } else { console.log("has not credentials"); }})
      navigator.credentials
        .get({ 'password': true })
        .then(credential => {
          if (!credential) { return; }
          if (credential.type == 'password') {
            document.querySelector('input[name=username]').value = credential.id;
            document.querySelector('input[name=password]').value = credential.password;
            document.getElementById('login').submit();
          }
      });
    }
  </script>
  </body>
</html>

f:id:pivot_root:20210508190951p:plain