HTTP Permissions-Policy otp-credentials

Typ

Die otp-credentials-Direktive steuert den Zugriff auf die WebOTP API zum automatischen Auslesen von SMS-OTP-Codes.

Syntax

Die Direktive definiert eine Allowlist für Ursprünge, die OTP-Credentials abfragen dürfen.

http
Permissions-Policy: otp-credentials=(self)
Permissions-Policy: otp-credentials=(self "https://auth.sms-2fa.com")
Permissions-Policy: otp-credentials=()

Direktiven

Die Direktive unterstützt Standard-Allowlist-Werte für präzise Zugriffssteuerung.

self
Erlaubt WebOTP-Zugriff nur für das Hauptdokument des gleichen Ursprungs. Eingebettete iFrames von anderen Ursprüngen werden blockiert.
origin-list
Liste von Ursprüngen in Anführungszeichen, z.B. "https://verification.example.com", die zusätzlich zum Hauptdokument WebOTP verwenden dürfen. Für 2FA-Widgets.

Beispiele

Die folgenden Beispiele zeigen typische Anwendungsfälle für SMS-2FA, Phone-Verification und Onboarding-Flows.

Login mit SMS-2FA und WebOTP

Eine Login-Seite nutzt WebOTP API für automatisches Auslesen des SMS-Verification-Codes.

http
HTTP/1.1 200 OK
Content-Type: text/html
Permissions-Policy: otp-credentials=(self)

<!DOCTYPE html>
<html>
<head><title>2FA Login</title></head>
<body>
  <input type="text" id="otp" autocomplete="one-time-code">
  <script>
    if ('OTPCredential' in window) {
      navigator.credentials.get({
        otp: {transport: ['sms']},
        signal: abortController.signal
      }).then(otp => {
        document.getElementById('otp').value = otp.code;
        // Auto-submit form
      });
    }
  </script>
</body>
</html>

E-Commerce mit Phone-Verification-Widget

Eine E-Commerce-Plattform erlaubt einem Verification-Widget WebOTP-Zugriff für Checkout.

http
HTTP/1.1 200 OK
Content-Type: text/html
Permissions-Policy: otp-credentials=(self "https://verify.sms-service.example.com")

<!DOCTYPE html>
<html>
<head><title>Checkout</title></head>
<body>
  <iframe src="https://verify.sms-service.example.com/widget"
          allow="otp-credentials"></iframe>
</body>
</html>

REST-API ohne OTP-Credentials

Ein API-Endpunkt deaktiviert alle Credential-APIs für maximale Sicherheit.

http
HTTP/1.1 200 OK
Content-Type: application/json
Permissions-Policy: otp-credentials=(), publickey-credentials-get=()

{
  "status": "success",
  "verification_method": "manual"
}

Vorteile für die Systemarchitektur

  • Verbessert UX durch automatisches SMS-Code-Ausfüllen ohne Clipboard
  • Verhindert unerwünschten OTP-Zugriff durch Drittanbieter-iFrames
  • Reduziert Phishing-Risiken durch Domain-Binding in SMS-Format
  • Unterstützt nahtlose 2FA-Flows auf mobilen Geräten

Spezifikation

Definiert in der WICG WebOTP API Spezifikation. Chromium-basierte Browser. Erfordert spezielle SMS-Format mit @domain und #code Syntax.

Weitere Spezifikationen

Permissions-Policy Header, Content-Security-Policy Header