Reject raw APDU commands in KMP NFC bridge#1839
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughThis PR implements a security boundary policy that rejects caller-supplied APDU commands at the KMP NFC bridge level. The Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/kmp-sdk/shared/src/commonTest/kotlin/xyz/self/sdk/handlers/NfcApduPolicyTest.kt (1)
14-95: Good test coverage with one potential gap.The tests cover the key scenarios:
- Standard params (no
apduCommands) → allowed- Empty
apduCommandsarray → allowed- Non-empty
apduCommands→ rejected with correct code/message- Malformed
apduCommands(string) → rejectedOne scenario not explicitly tested:
"apduCommands": null(JsonNull). The policy handles this case (Line 19 in NfcApduPolicy.kt), but there's no test asserting it. Consider adding for completeness:🧪 Optional: Add JsonNull test case
`@Test` fun requireSupportedParams_allowsNullApduCommands() { NfcApduPolicy.requireSupportedParams( params( """ { "passportNumber": "L898902C3", "dateOfBirth": "690806", "dateOfExpiry": "060815", "apduCommands": null } """.trimIndent(), ), ) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/kmp-sdk/shared/src/commonTest/kotlin/xyz/self/sdk/handlers/NfcApduPolicyTest.kt` around lines 14 - 95, Add a test that verifies NfcApduPolicy.requireSupportedParams accepts a JsonNull apduCommands value: create a new test (e.g. requireSupportedParams_allowsNullApduCommands) that calls NfcApduPolicy.requireSupportedParams with the same params helper (params(rawJson)) but with "apduCommands": null in the JSON payload; this should assert no exception is thrown (same style as the existing allowed-case tests) to cover the JsonNull branch handled in NfcApduPolicy.requireSupportedParams.specs/projects/sdk/workstreams/native-shells/plans/NS-04-apdu-allowlist.md (1)
1-4: Minor: Title says "Allowlist" but implementation rejects all APDU commands.The plan title references "APDU Allowlist" but the actual implementation rejects all caller-supplied APDU commands (no allowlist exists—it's a complete deny). The content correctly describes the rejection policy, so this is just a naming inconsistency. Consider updating to "APDU Rejection" or "APDU Boundary Policy" for clarity, though this is low priority.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@specs/projects/sdk/workstreams/native-shells/plans/NS-04-apdu-allowlist.md` around lines 1 - 4, The document title "APDU Allowlist in KMP NFC Bridge Handler" is misleading because the implementation rejects all APDU commands; update the header to reflect the actual behavior (e.g., "APDU Rejection in KMP NFC Bridge Handler" or "APDU Boundary/Rejection Policy") and adjust any short description lines (the one-line summary after the header and the metadata block) so the name and status consistently describe the deny-all APDU policy used by this plan.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@packages/kmp-sdk/shared/src/commonTest/kotlin/xyz/self/sdk/handlers/NfcApduPolicyTest.kt`:
- Around line 14-95: Add a test that verifies
NfcApduPolicy.requireSupportedParams accepts a JsonNull apduCommands value:
create a new test (e.g. requireSupportedParams_allowsNullApduCommands) that
calls NfcApduPolicy.requireSupportedParams with the same params helper
(params(rawJson)) but with "apduCommands": null in the JSON payload; this should
assert no exception is thrown (same style as the existing allowed-case tests) to
cover the JsonNull branch handled in NfcApduPolicy.requireSupportedParams.
In `@specs/projects/sdk/workstreams/native-shells/plans/NS-04-apdu-allowlist.md`:
- Around line 1-4: The document title "APDU Allowlist in KMP NFC Bridge Handler"
is misleading because the implementation rejects all APDU commands; update the
header to reflect the actual behavior (e.g., "APDU Rejection in KMP NFC Bridge
Handler" or "APDU Boundary/Rejection Policy") and adjust any short description
lines (the one-line summary after the header and the metadata block) so the name
and status consistently describe the deny-all APDU policy used by this plan.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f5a5ea37-88b8-4eda-8583-f698b15f7639
📒 Files selected for processing (6)
packages/kmp-sdk/shared/src/androidMain/kotlin/xyz/self/sdk/handlers/NfcBridgeHandler.ktpackages/kmp-sdk/shared/src/commonMain/kotlin/xyz/self/sdk/handlers/NfcApduPolicy.ktpackages/kmp-sdk/shared/src/commonTest/kotlin/xyz/self/sdk/handlers/NfcApduPolicyTest.ktpackages/kmp-sdk/shared/src/iosMain/kotlin/xyz/self/sdk/handlers/NfcBridgeHandler.ktspecs/projects/sdk/workstreams/native-shells/SPEC.mdspecs/projects/sdk/workstreams/native-shells/plans/NS-04-apdu-allowlist.md
Summary
This PR hardens the KMP NFC bridge by rejecting caller-supplied apduCommands at the handler boundary on both Android and iOS. The KMP SDK continues to support only the
existing high-level passport scan flow, which keeps the native handler thin and avoids exposing raw APDU passthrough.
It adds shared tests covering accepted standard scan params and rejected APDU input, and updates the native-shells plan/spec to mark NS-04 complete and document the
implemented policy.
Test plan
Native Consolidation Checklist
cd app && yarn jest:run/yarn workspace @selfxyz/rn-sdk-test-app test)Summary by CodeRabbit
Bug Fixes
Tests