Skip to content

Commit dea1d85

Browse files
committed
Addressed review comments from @nandan.prabhu
1 parent 44d3d41 commit dea1d85

7 files changed

Lines changed: 253 additions & 217 deletions

File tree

‎auth0/src/main/java/com/auth0/android/embedded/authorize/NextActionMapper.kt‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private fun Map<String, Any>.toNextAction(): NextAction? {
4646
?: return dropped(raw, AUTHN_PARAMS_PUBLIC_KEY_KEY)
4747
val challenge = params[CHALLENGE_KEY] as? String
4848
?: return dropped(raw, "$AUTHN_PARAMS_PUBLIC_KEY_KEY.$CHALLENGE_KEY")
49-
val timeout = params[TIMEOUT_KEY] as? Long
49+
val timeout = (params[TIMEOUT_KEY] as? Number)?.toWholeLong()
5050
?: return dropped(raw, "$AUTHN_PARAMS_PUBLIC_KEY_KEY.$TIMEOUT_KEY")
5151
val rpId = params[RP_ID_KEY] as? String
5252
?: return dropped(raw, "$AUTHN_PARAMS_PUBLIC_KEY_KEY.$RP_ID_KEY")
@@ -167,6 +167,9 @@ private fun Map<String, Any>.toSignupPassword(): SignupPassword? {
167167
private fun Number.toWholeInt(): Int? =
168168
toDouble().takeIf { it % 1.0 == 0.0 && it in Int.MIN_VALUE.toDouble()..Int.MAX_VALUE.toDouble() }?.toInt()
169169

170+
private fun Number.toWholeLong(): Long? =
171+
toDouble().takeIf { it % 1.0 == 0.0 && it in Long.MIN_VALUE.toDouble()..Long.MAX_VALUE.toDouble() }?.toLong()
172+
170173
private fun passwordCharacterType(value: String): SignupPasswordComplexity.CharacterType? = when (value) {
171174
"lowercase" -> SignupPasswordComplexity.CharacterType.LOWERCASE
172175
"uppercase" -> SignupPasswordComplexity.CharacterType.UPPERCASE

‎auth0/src/main/java/com/auth0/android/embedded/passkey/PasskeyAssertion.kt‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ private const val MAX_CLIENT_DATA_JSON_LENGTH = 1000
2222
private const val MAX_AUTHENTICATOR_DATA_LENGTH = 750
2323
private const val MAX_SIGNATURE_LENGTH = 750
2424
private const val MAX_USER_HANDLE_LENGTH = 100
25+
private const val MAX_CLIENT_EXTENSION_RESULTS = 20
2526

2627
private 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

Comments
 (0)