> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Security scanning (rnsec)

We use [rnsec](https://www.rnsec.dev/) to scan the React Native / Expo codebase for common security issues.

## Commands

```bash
bun run security:scan
```

Writes `rnsec-report.json` / `rnsec-report.html` at the repo root (gitignored) (`bunx rnsec scan`). Config lives in [`.rnsec.json`](https://github.com/leapgame/leap-sim-piano/blob/f794b594016038c483e2d20b6af56aea0ae1b982/.rnsec.json). rnsec exits non-zero when it reports a finding, which fails the hook / CI job; accept a risk by adding it to `ignoredRules` or `exclude` with a reason below. `bunx rnsec scan --changed-files <ref>` scans only changed files.

## Where it runs

- **lefthook pre-commit** (`security` job): a finding aborts the commit. See [`lefthook.yml`](https://github.com/leapgame/leap-sim-piano/blob/f794b594016038c483e2d20b6af56aea0ae1b982/lefthook.yml).
- **GitLab `validate` job**: after install + typecheck and before the unit tests; both iOS build jobs `need` it. The report is kept as the `rnsec-report.html` artifact. See [ci-cd.md](/docs/ci-cd.md).

## Accepted risks (`ignoredRules`)

| Rule                               | Why we accept it                                                                                                                                                                                                                                                        |
| ---------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `IOS_ATS_DISABLED`                 | `NSAllowsArbitraryLoads` was required by the former IronSource LevelPlay networks; kept for review until the AdMob mediation networks are chosen — see `app.config.ts` and [admob-integration.md](/docs/admob-integration.md#10-infoplist--skadnetwork--ats) |
| `ANDROID_EXPORTED_COMPONENT`       | Expo `MainActivity` must be exported for the launcher                                                                                                                                                                                                                   |
| `ANDROID_INTENT_FILTER_PERMISSIVE` | Required for `magicpiano://` / `exp+magic-piano` deeplinks; URLs are validated in JS                                                                                                                                                                                    |
| `THIRD_PARTY_SDK_RISK`             | AppsFlyer is intentional (attribution / ROI360); Segment hits on unrelated files are false positives                                                                                                                                                                    |

## Exclusions

- `**/ios/Pods/**` — third-party ad OM SDK JS (`Function('return this')`)
- `**/song-config.ts` — public publish-to-web Google Sheet IDs, not credentials
- `tools/**`, `packages/*/visualizer/**` — desktop/dev tooling that never ships in the app; also build output (`**/build`, `**/dist`, `**/out`, `**/release`)

## App hardening helpers

| Helper                          | Purpose                                                                     |
| ------------------------------- | --------------------------------------------------------------------------- |
| `safeErrorMessage`              | Log only `Error.message` / `String(error)` — never raw error objects        |
| `fetchWithTimeout`              | `AbortController`-backed fetch timeouts                                     |
| `openHttpsUrl`                  | Allowlist `https:` before `Linking.openURL`                                 |
| `expo-crypto` `getRandomValues` | Secure random on RN (do **not** use the Web `crypto` global — Biome-banned) |

***

<small>Source: [`docs/security.md`](https://github.com/leapgame/leap-sim-piano/blob/f794b594016038c483e2d20b6af56aea0ae1b982/docs/security.md)</small>
