@@ -22,6 +22,7 @@ private const val MAX_CLIENT_DATA_JSON_LENGTH = 1000
2222private const val MAX_AUTHENTICATOR_DATA_LENGTH = 750
2323private const val MAX_SIGNATURE_LENGTH = 750
2424private const val MAX_USER_HANDLE_LENGTH = 100
25+ private const val MAX_CLIENT_EXTENSION_RESULTS = 20
2526
2627private val AUTHENTICATOR_ATTACHMENTS = setOf (" platform" , " cross-platform" )
2728
@@ -42,13 +43,14 @@ internal class InvalidPasskeyResponseException(message: String) : IllegalArgumen
4243
4344/* *
4445 * Builds the `authn_response` object from the `authenticationResponseJson` the platform returns,
45- * keeping only the fields `/e/authorize` accepts and enforcing its required fields, `type` value and
46- * length limits. `authenticatorAttachment` is kept only when it is a known value;
47- * `clientExtensionResults` is forwarded unchanged when it is an object.
46+ * keeping only the fields `/e/authorize` accepts. It enforces the required fields, the `type` value and the
47+ * length limits of the `PasskeyAssertion.json` schema of the embedded authorize API, and must be kept in line
48+ * with them. `authenticatorAttachment` is kept only when it is a known value; `clientExtensionResults` is
49+ * forwarded unchanged when it is an object with at most 20 entries, and left out otherwise.
4850 *
49- * The rules mirror the `PasskeyAssertion.json` schema of the embedded authorize API, and must be kept in
50- * line with it. They are checked here because the server answers a request that breaks the schema with a
51- * terminal `invalid_request`, which ends the flow, while a local failure leaves the flow open .
51+ * These are checked here because the server answers a request that breaks the schema with a terminal
52+ * `invalid_request`, which ends the flow, while a local failure leaves the flow open. The server applies
53+ * the schema's other rules, such as the characters a string may contain; the platform's responses meet them .
5254 *
5355 * @throws InvalidPasskeyResponseException if the assertion doesn't satisfy the schema.
5456 */
@@ -85,6 +87,7 @@ internal fun passkeyAuthnResponse(authenticationResponseJson: String): Map<Strin
8587 ?.takeIf { it in AUTHENTICATOR_ATTACHMENTS }
8688 ?.let { put(AUTHENTICATOR_ATTACHMENT_KEY , it) }
8789 (assertion.get(CLIENT_EXTENSION_RESULTS_KEY ) as ? JsonObject )
90+ ?.takeIf { it.size() <= MAX_CLIENT_EXTENSION_RESULTS }
8891 ?.let { put(CLIENT_EXTENSION_RESULTS_KEY , it) }
8992 }
9093}
0 commit comments