packages feed

shomei-webauthn 0.3.0.0 → 0.4.0.0

raw patch · 5 files changed

+55/−11 lines, 5 filesdep ~shomei-coredep ~shomei-webauthnPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: shomei-core, shomei-webauthn

API changes (from Hackage documentation)

Files

CHANGELOG.md view
@@ -4,6 +4,16 @@ [PVP](https://pvp.haskell.org/) and is versioned independently of the other Shōmei packages. +## 0.4.0.0 — 2026-11-25++- **Breaking:** require the Shōmei 0.4 API series.++- Fix #13: require discoverable credentials for new enrollment, independently of UV policy.+  The existing encoder emits `residentKey: "required"` and `requireResidentKey: true` in+  browser and persisted options. Devices without resident-key support now fail creation;+  existing non-discoverable credentials still support known-account step-up and require+  replacement enrollment for passwordless login. No schema or configuration API changes.+ ## 0.3.0.0 — 2026-11-05  - **Breaking:** internal dependency bounds follow the 0.3 API series.
shomei-webauthn.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: shomei-webauthn-version: 0.3.0.0+version: 0.4.0.0 synopsis:   WebAuthn (passkey) registration/authentication ceremony interpreter @@ -61,7 +61,7 @@     effectful >=2.5 && <2.8,     effectful-core >=2.5 && <2.8,     mtl >=2.3 && <2.4,-    shomei-core ^>=0.3.0.0,+    shomei-core ^>=0.4.0.0,     text >=2.0 && <2.2,     time >=1.12 && <1.15,     time-hourglass >=0.3 && <0.4,@@ -87,8 +87,8 @@     effectful >=2.5 && <2.8,     effectful-core >=2.5 && <2.8,     ram >=0.22 && <0.23,-    shomei-core ^>=0.3.0.0,-    shomei-webauthn ^>=0.3.0.0,+    shomei-core ^>=0.4.0.0,+    shomei-webauthn ^>=0.4.0.0,     tasty >=1.4 && <1.6,     tasty-hunit >=0.10 && <0.11,     text >=2.0 && <2.2,
src/Shomei/WebAuthn/Ceremony.hs view
@@ -110,7 +110,9 @@               Just                 WA.AuthenticatorSelectionCriteria                   { WA.ascAuthenticatorAttachment = Nothing,-                    WA.ascResidentKey = WA.ResidentKeyRequirementDiscouraged,+                    -- Passwordless login supplies no credential IDs, so every new+                    -- enrollment must be discoverable independently of UV policy.+                    WA.ascResidentKey = WA.ResidentKeyRequirementRequired,                     WA.ascUserVerification = mapUV (userVerification cfg)                   },             WA.corHints = [],
test/Shomei/WebAuthn/CeremonySpec.hs view
@@ -17,7 +17,7 @@ import Effectful (runEff) import Shomei.Config   ( AttestationPolicy (..),-    UserVerificationPolicy (UVDiscouraged, UVRequired),+    UserVerificationPolicy (..),     WebAuthnConfig (attestation, origins, userVerification),     defaultWebAuthnConfig,   )@@ -51,7 +51,12 @@       testCase "begin authentication produces a round-tripping options blob" beginAuthenticationRoundTrips,       testCase "passwordless authentication requires UV even when step-up discourages it" passwordlessRequiresUv,       testCase "complete registration on malformed credential JSON fails closed" completeRejectsGarbage,-      testCase "empty origins fail closed before credential decoding" emptyOriginsFailClosed+      testCase "empty origins fail closed before credential decoding" emptyOriginsFailClosed,+      testGroup+        "registration requires discoverable credentials independently of UV"+        [ testCase (show uv) (registrationRequiresResidency uv expectedUv)+        | (uv, expectedUv) <- [(UVPreferred, "preferred"), (UVRequired, "required"), (UVDiscouraged, "discouraged")]+        ]     ]  sampleUser :: CredentialUserInfo@@ -68,6 +73,18 @@     runEff . runWebAuthnCeremonyLibrary defaultWebAuthnConfig $ beginRegistrationCeremony sampleUser []   assertBool "registration optionsBlob is non-empty" (not (BC.null blob))   assertBool "registration optionsBlob round-trips through webauthn-json" (registrationBlobRoundTrips blob)++registrationRequiresResidency :: UserVerificationPolicy -> Text -> IO ()+registrationRequiresResidency uv expectedUv = do+  let cfg = defaultWebAuthnConfig {userVerification = uv}+  BeginCeremony {optionsJson, optionsBlob} <-+    runEff . runWebAuthnCeremonyLibrary cfg $ beginRegistrationCeremony sampleUser []+  let stored = eitherDecodeStrict' optionsBlob :: Either String Value+      selection = parseEither (withObject "options" (\o -> o .: "authenticatorSelection" >>= withObject "selection" (\s -> (,,) <$> s .: "residentKey" <*> s .: "requireResidentKey" <*> s .: "userVerification")))+      expected = Right ("required" :: Text, True, expectedUv)+  selection optionsJson @?= expected+  (stored >>= selection) @?= expected+  stored @?= Right optionsJson  beginAuthenticationRoundTrips :: IO () beginAuthenticationRoundTrips = do
test/Shomei/WebAuthn/WorkflowSpec.hs view
@@ -6,10 +6,11 @@  import Control.Monad (forM_) import Data.Aeson (Value, encode)-import Data.Aeson.Types (parseMaybe, withObject, (.:))+import Data.Aeson.Types (parseEither, parseMaybe, withObject, (.:), (.:?)) import Data.ByteString.Lazy qualified as LBS import Data.IORef (IORef, modifyIORef', newIORef, readIORef) import Data.Map.Strict qualified as Map+import Data.Text (Text) import Data.Time (UTCTime (..), addUTCTime, fromGregorian) import Effectful (Eff, IOE, liftIO, runEff, (:>)) import Effectful.Dispatch.Dynamic (interpose)@@ -25,7 +26,7 @@ import Shomei.Mfa.Workflow (MfaCompletion (..), beginPasswordlessLogin, completeMfa, completePasswordlessLogin) import Shomei.Passkey.Ceremony.Port import Shomei.Passkey.Ceremony.Store (putPendingCeremony)-import Shomei.Passkey.Domain (CeremonyKind (..), PasskeyCredential (..), PendingCeremony (..), SignatureCounter (..), b64urlDecode)+import Shomei.Passkey.Domain (CeremonyKind (..), PasskeyCredential (..), PendingCeremony (..), SignatureCounter (..), b64urlDecode, b64urlEncode) import Shomei.Passkey.Workflow (beginPasskeyRegistration, completePasskeyRegistration) import Shomei.Session.Authentication.Workflow (LoginResult (..), MfaChallenge (..), login, signup) import Shomei.Session.Command (ClientContext (..), LoginCommand (..), ProofContext (..), SignupCommand (..))@@ -73,7 +74,9 @@ seed = do   ref <- newIORef (emptyWorld fixedTime)   (user, _) <- right =<< runHybrid ref (signup cfg (SignupCommand fixtureLoginId Nothing fixturePassword Nothing))-  (cid, options) <- right =<< runHybrid ref (beginPasskeyRegistration cfg user.userId)+  (cid, options) <- right =<< runHybrid ref (beginPasskeyRegistration cfg user.userId Nothing)+  parseEither (withObject "options" (\o -> o .: "authenticatorSelection" >>= withObject "selection" (\s -> (,) <$> s .: "residentKey" <*> s .: "requireResidentKey"))) options+    @?= Right ("required" :: Text, True)   handle <- case parseMaybe (withObject "options" (\o -> o .: "user" >>= withObject "user" (.: "id"))) options of     Just value -> right (b64urlDecode value)     Nothing -> assertFailure "fixture options lack user handle"@@ -83,6 +86,14 @@   replay @?= Left PendingCeremonyNotFound   pure (ref, user, policy) +-- The signed fixture checks the server contract; browser discovery is verified+-- separately with a resident-capable virtual authenticator (ExecPlan 74).+assertPasswordlessOptions :: Value -> IO ()+assertPasswordlessOptions options = do+  allowed <- right (parseEither (withObject "options" (.:? "allowCredentials")) options :: Either String (Maybe [Value]))+  assertBool "passwordless begin does not restrict credential discovery" (maybe True null allowed)+  parseEither (withObject "options" (.: "userVerification")) options @?= Right ("required" :: Text)+ tests :: TestTree tests =   testGroup@@ -92,11 +103,14 @@         challenge <- right =<< runHybrid ref (login cfg (ClientContext (ClientIp "fixture") (AccountKey "fixture-user")) (LoginCommand fixtureLoginId fixturePassword False))         case challenge of           MfaRequired MfaChallenge {ceremonyId, options} -> do+            parseEither (withObject "options" (\o -> o .: "allowCredentials" >>= traverse (withObject "credential" (.: "id")))) options+              @?= Right [b64urlEncode credentialBytes]             _ <- right =<< runHybrid ref (completeMfa cfg proof ceremonyId (MfaPasskey (assertionResponse options policy {responseCounter = 1, responseFlags = 1})))             replay <- runHybrid ref (completeMfa cfg proof ceremonyId (MfaPasskey (assertionResponse options policy {responseCounter = 1})))             replay @?= Left PendingCeremonyNotFound           _ -> assertFailure "expected password step-up"         (cid, options) <- right =<< runHybrid ref (beginPasswordlessLogin cfg)+        assertPasswordlessOptions options         (resolved, _) <- right =<< runHybrid ref (completePasswordlessLogin cfg proof cid (assertionResponse options policy {responseCounter = 2}))         resolved.userId @?= user.userId         world <- readIORef ref@@ -113,6 +127,7 @@           let run :: Eff InMemoryPorts a -> IO a               run = runInMemory ref . realCeremonies cfg.webauthnConfig {userVerification = uv}           (cid, options) <- right =<< run (beginPasswordlessLogin cfg)+          assertPasswordlessOptions options           failed <- run (completePasswordlessLogin cfg proof cid (assertionResponse options policy {responseCounter = 1, responseFlags = 1}))           failed @?= Left MfaAssertionInvalid           replay <- run (completePasswordlessLogin cfg proof cid (assertionResponse options policy {responseCounter = 1}))@@ -127,7 +142,7 @@         (cid, options) <- runHybrid ref do           BeginCeremony {optionsJson, optionsBlob} <- beginAuthenticationCeremony UVRequired []           cid <- genCeremonyId-          putPendingCeremony (PendingCeremony cid (Just bob.userId) AuthenticationCeremony optionsBlob fixedTime (addUTCTime 300 fixedTime))+          putPendingCeremony (PendingCeremony (Just 0) Nothing cid (Just bob.userId) AuthenticationCeremony optionsBlob fixedTime (addUTCTime 300 fixedTime))           pure (cid, optionsJson)         wrongOwner <- runHybrid ref (completeMfa cfg proof cid (MfaPasskey (assertionResponse options policy {responseCounter = 1})))         wrongOwner @?= Left MfaAssertionInvalid