nativekeel 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@ Health check for React Native and Expo apps. One command, no install, no account
6
6
  npx nativekeel
7
7
  ```
8
8
 
9
- **What's new in 0.1.12:** hacking risks mapped to OWASP MASVS: open Firebase rules, TLS certificate checks turned off, hardcoded keys and weak crypto, tokens in plain storage, with a security overview in every report. **0.1.10:** every report opens with *Start here*, the three most urgent first steps; missing iOS permission texts (a crash and an App Review rejection) are caught. Recent releases added known vulnerabilities in the exact versions you ship, password leaks into logs and databases, unsafe WebViews, open Android components, plain-HTTP API calls and runtime crash risks. Tuned on 280+ open-source React Native and Expo apps to keep false alarms out. [All releases →](https://nativekeel.com/changelog)
9
+ **What's new in 0.1.13:** performance traps (nested lists, JS-thread animations, release console logs, heavy imports, oversized images) and reverse-engineering exposure (source maps in the app, Hermes/R8 off). **0.1.12:** hacking risks mapped to OWASP MASVS: open Firebase rules, TLS certificate checks turned off, hardcoded keys and weak crypto, tokens in plain storage, with a security overview in every report. **0.1.10:** every report opens with *Start here*, the three most urgent first steps; missing iOS permission texts (a crash and an App Review rejection) are caught. Recent releases added known vulnerabilities in the exact versions you ship, password leaks into logs and databases, unsafe WebViews, open Android components, plain-HTTP API calls and runtime crash risks. Tuned on 280+ open-source React Native and Expo apps to keep false alarms out. [All releases →](https://nativekeel.com/changelog)
10
10
 
11
11
  It answers the questions that decide whether your app can still ship:
12
12
 
@@ -20,6 +20,8 @@ It answers the questions that decide whether your app can still ship:
20
20
  - **Do you ship known vulnerabilities?** Advisories from the GitHub Advisory Database for the exact versions in your lockfile or `node_modules`. Advisories that only affect Node.js servers are kept, at low severity.
21
21
  - **Can someone break in?** Grouped by OWASP MASVS: Firebase Realtime Database/Firestore/Storage rules open to anyone (or in test mode), TLS certificate checks turned off in native code, hardcoded encryption keys, MD5/SHA-1 on passwords, ECB mode, `Math.random` for nonces and salts. These are static checks: they catch the common, detectable mistakes, not everything a penetration test of the running app would.
22
22
  - **Can someone read your users' data?** Passwords that flow into crash reports, analytics, remote databases or plain AsyncStorage (followed through intermediate variables), WebViews that let page scripts read local files or load HTTP into HTTPS, Android backups that copy tokens, Android components any app can start, API calls over plain HTTP, auth tokens in unencrypted storage.
23
+ - **Is it slow or heavy?** A FlatList inside a ScrollView (no virtualization), animations with `useNativeDriver: false`, `console.log` left in release builds, whole-library `lodash`/`moment` imports, images over 500 KB that the app requires. Static signs to measure on a device, not a profiler.
24
+ - **Can it be taken apart?** Source maps packaged into the app, Hermes or R8 off in release (OWASP MASVS-RESILIENCE). Obfuscation only slows an attacker down; keep secrets and checks on the server.
23
25
  - **Will it crash at runtime?** Reanimated without its Babel plugin or `react-native-worklets`, mixed `@react-native-firebase/*` or `@react-navigation/*` majors, a second copy of React or React Native inside a dependency, Kotlin modules that cannot load through the New Architecture interop layer, AppDelegate setups that crash in Release, camera/photos/location access without the Info.plist description iOS requires.
24
26
  - **Leftovers from old templates?** Flipper, JavaScriptCore instead of Hermes.
25
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nativekeel",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "Health check for React Native and Expo apps: upgrade blockers, store deadlines, crash risks, vulnerable dependencies and leaked secrets, with a step-by-step upgrade plan.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/analyze.js CHANGED
@@ -5,7 +5,8 @@ import { createRegistry, fetchJson } from './registry.js';
5
5
  import { scanSecrets } from './secrets.js';
6
6
  import { nativeChecks } from './native.js';
7
7
  import { stabilityChecks } from './stability.js';
8
- import { vulnerableDependencies, passwordLeaks, webViewRisks, androidBackup, exportedComponents, plainHttpCalls, cloudRules, insecureTls, weakCrypto, tokenStorage, masvsOf, MASVS_GROUPS } from './security.js';
8
+ import { performanceChecks } from './performance.js';
9
+ import { vulnerableDependencies, passwordLeaks, webViewRisks, androidBackup, exportedComponents, plainHttpCalls, cloudRules, insecureTls, weakCrypto, tokenStorage, reverseEngineering, masvsOf, MASVS_GROUPS } from './security.js';
9
10
  import { lockedVersions } from './lockfile.js';
10
11
  import { findUnused, filesImportingWith } from './usage.js';
11
12
  import { matchKnownIssues, compareVersions } from './known-issues.js';
@@ -403,9 +404,11 @@ export async function analyze(project, { get, now = new Date(), offline: forcedO
403
404
  // 7. Secrets
404
405
  // Setups that build and then crash at runtime.
405
406
  for (const f of stabilityChecks(project)) add(f);
407
+ // Static signs of performance problems.
408
+ for (const f of performanceChecks(project)) add(f);
406
409
 
407
410
  // Security beyond leaked keys.
408
- for (const f of [...passwordLeaks(project.root), ...webViewRisks(project.root), ...androidBackup(project.root), ...exportedComponents(project.root), ...plainHttpCalls(project.root), ...cloudRules(project.root, project.deps, now), ...insecureTls(project.root), ...weakCrypto(project.root), ...tokenStorage(project.root)]) add(f);
411
+ for (const f of [...passwordLeaks(project.root), ...webViewRisks(project.root), ...androidBackup(project.root), ...exportedComponents(project.root), ...plainHttpCalls(project.root), ...cloudRules(project.root, project.deps, now), ...insecureTls(project.root), ...weakCrypto(project.root), ...tokenStorage(project.root), ...reverseEngineering(project.root, project)]) add(f);
409
412
  if (!forcedOffline) {
410
413
  // Exact versions only (installed, else the lockfile): a range would be a guess.
411
414
  const locked = lockedVersions(project.root, project.deps);
@@ -0,0 +1,163 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ // Performance problems you can see in the code: things that make lists stutter, animations run
5
+ // on the JavaScript thread, or the app download heavier than it needs to be. Runtime profiling
6
+ // (frame drops, start-up time) needs a device; these are the static signs.
7
+
8
+ const SKIP_DIRS = new Set(['node_modules', '.git', 'Pods', 'build', '.gradle', 'DerivedData', '.expo', 'dist', 'coverage', 'vendor', '__tests__', '__mocks__', 'e2e', 'android', 'ios']);
9
+ const JS_EXT = /\.(?:[cm]?[jt]sx?)$/;
10
+
11
+ function* walk(dir, test) {
12
+ let entries;
13
+ try {
14
+ entries = fs.readdirSync(dir, { withFileTypes: true });
15
+ } catch {
16
+ return;
17
+ }
18
+ for (const e of entries) {
19
+ if (e.isDirectory()) {
20
+ if (!SKIP_DIRS.has(e.name) && !e.name.startsWith('.')) yield* walk(path.join(dir, e.name), test);
21
+ } else if (test.test(e.name) && !/\.(test|spec)[._]/.test(e.name)) {
22
+ yield path.join(dir, e.name);
23
+ }
24
+ }
25
+ }
26
+
27
+ const read = (file) => {
28
+ try {
29
+ return fs.statSync(file).size > 512 * 1024 ? '' : fs.readFileSync(file, 'utf8');
30
+ } catch {
31
+ return '';
32
+ }
33
+ };
34
+
35
+ // The props text of the JSX tag starting at `start` (up to its closing `>` or `/>`, skipping
36
+ // `>` inside {...} expressions such as arrow functions).
37
+ function tagProps(text, start) {
38
+ let depth = 0;
39
+ for (let i = start + 1; i < text.length && i < start + 4000; i++) {
40
+ const c = text[i];
41
+ if (c === '{') depth++;
42
+ else if (c === '}') depth--;
43
+ else if (c === '>' && depth === 0) return { props: text.slice(start, i), end: i + 1 };
44
+ }
45
+ return { props: text.slice(start, start + 4000), end: start + 4000 };
46
+ }
47
+
48
+ export function performanceChecks(project) {
49
+ const root = project.root;
50
+ const findings = [];
51
+ const nested = [];
52
+ let jsDriver = 0;
53
+ let jsDriverAt = null;
54
+ let logs = 0;
55
+ const heavyImports = new Map();
56
+ for (const file of walk(root, JS_EXT)) {
57
+ const text = read(file);
58
+ if (!text) continue;
59
+ const rel = path.relative(root, file);
60
+ const code = text.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/[^\n]*/g, '');
61
+
62
+ // A vertical FlatList/SectionList inside a vertical ScrollView renders every item at once
63
+ // (React Native warns "VirtualizedLists should never be nested").
64
+ // JSX tags only: not TypeScript generics like useRef<ScrollView>(null).
65
+ for (const m of code.matchAll(/(?<![\w.$])<ScrollView\b/g)) {
66
+ const open = tagProps(code, m.index);
67
+ if (/\bhorizontal\b/.test(open.props)) continue;
68
+ const close = code.indexOf('</ScrollView>', open.end);
69
+ if (close < 0) continue;
70
+ const body = code.slice(open.end, close);
71
+ const im = body.match(/(?<![\w.$])<(FlatList|SectionList|FlashList)\b/);
72
+ if (!im) continue;
73
+ const inner = tagProps(body, im.index);
74
+ if (!/\bhorizontal\b/.test(inner.props) && !/scrollEnabled\s*=\s*\{\s*false\s*\}/.test(inner.props)) {
75
+ nested.push(`${rel}:${code.slice(0, m.index).split('\n').length}`);
76
+ }
77
+ }
78
+ // Animations driven from JavaScript: every frame crosses to the JS thread.
79
+ for (const m of code.matchAll(/useNativeDriver\s*:\s*false/g)) {
80
+ jsDriver++;
81
+ jsDriverAt = jsDriverAt || `${rel}:${code.slice(0, m.index).split('\n').length}`;
82
+ }
83
+ logs += (code.match(/\bconsole\.(?:log|debug|info)\s*\(/g) || []).length;
84
+ // Whole-library imports of packages with per-function or lighter alternatives.
85
+ if (/from\s+['"]lodash['"]|require\(\s*['"]lodash['"]\s*\)/.test(code)) heavyImports.set('lodash', heavyImports.get('lodash') || rel);
86
+ if (/from\s+['"]moment['"]|require\(\s*['"]moment['"]\s*\)/.test(code)) heavyImports.set('moment', heavyImports.get('moment') || rel);
87
+ }
88
+
89
+ if (nested.length) {
90
+ findings.push({
91
+ id: 'perf-nested-lists',
92
+ severity: 'medium',
93
+ area: 'performance',
94
+ title: `A list inside a ScrollView renders every item at once (${nested[0]}${nested.length > 1 ? ` and ${nested.length - 1} more` : ''})`,
95
+ detail: 'A vertical FlatList/SectionList inside a vertical ScrollView loses virtualization: all rows mount up front, which costs memory and makes long lists stutter or crash on low-end Android. Use the list as the scroll container and move the other content into ListHeaderComponent/ListFooterComponent.',
96
+ fix: { kind: 'performance', step: `In \`${nested[0]}\`, make the FlatList the scroll container (ListHeaderComponent/ListFooterComponent) instead of nesting it in a ScrollView.` },
97
+ });
98
+ }
99
+ if (jsDriver >= 3) {
100
+ findings.push({
101
+ id: 'perf-js-driven-animations',
102
+ severity: 'low',
103
+ area: 'performance',
104
+ title: `${jsDriver} animations run on the JavaScript thread (useNativeDriver: false, e.g. ${jsDriverAt})`,
105
+ detail: 'Each frame of these animations waits for JavaScript, so they drop frames whenever the app is busy. Transform and opacity animations can use useNativeDriver: true; layout animations can move to Reanimated.',
106
+ fix: { kind: 'performance', step: 'Switch transform/opacity animations to `useNativeDriver: true` (or Reanimated for layout properties).' },
107
+ });
108
+ }
109
+ const babel = ['babel.config.js', '.babelrc', 'babel.config.json'].map((f) => read(path.join(root, f))).join('\n');
110
+ if (logs >= 30 && !/transform-remove-console|remove-console/.test(babel)) {
111
+ findings.push({
112
+ id: 'perf-console-in-release',
113
+ severity: 'low',
114
+ area: 'performance',
115
+ title: `${logs} console.log calls ship in the release build`,
116
+ detail: 'They run in production, slow the JavaScript thread in hot paths, and can write user data to the device log. Strip them from release builds with babel-plugin-transform-remove-console (keep console.error/warn).',
117
+ fix: { kind: 'performance', step: "Add `['transform-remove-console', { exclude: ['error', 'warn'] }]` to the production `env` of your Babel config." },
118
+ });
119
+ }
120
+ if (heavyImports.size) {
121
+ const advice = { lodash: 'import single functions (lodash/debounce) or use lodash-es with tree shaking', moment: 'use dayjs or date-fns (moment is in maintenance mode and pulls in all locales)' };
122
+ findings.push({
123
+ id: 'perf-heavy-imports',
124
+ severity: 'low',
125
+ area: 'performance',
126
+ title: `Whole-library imports of ${[...heavyImports.keys()].join(' and ')}`,
127
+ detail: `${[...heavyImports].map(([k, at]) => `${k} (${at}): ${advice[k]}`).join('; ')}. They add hundreds of KB to the bundle the app parses at start-up.`,
128
+ fix: { kind: 'performance', step: `Replace whole-library imports: ${[...heavyImports.keys()].map((k) => advice[k]).join('; ')}.` },
129
+ });
130
+ }
131
+
132
+ // Oversized images bundled with the app (require()d from code): download size and decode
133
+ // memory. Screenshots and docs in the repo are not part of the app, so only required files count.
134
+ const big = [];
135
+ const seen = new Set();
136
+ for (const file of walk(root, JS_EXT)) {
137
+ const text = read(file);
138
+ for (const m of text.matchAll(/require\(\s*['"](\.{1,2}\/[^'"]+\.(?:png|jpe?g|gif|webp))['"]\s*\)|import\s+\w+\s+from\s+['"](\.{1,2}\/[^'"]+\.(?:png|jpe?g|gif|webp))['"]/gi)) {
139
+ const img = path.resolve(path.dirname(file), m[1] || m[2]);
140
+ if (seen.has(img)) continue;
141
+ seen.add(img);
142
+ try {
143
+ const size = fs.statSync(img).size;
144
+ if (size > 500 * 1024) big.push({ rel: path.relative(root, img), size });
145
+ } catch {
146
+ // missing or @2x variant only
147
+ }
148
+ }
149
+ }
150
+ if (big.length) {
151
+ big.sort((a, b) => b.size - a.size);
152
+ const total = big.reduce((s, b) => s + b.size, 0);
153
+ findings.push({
154
+ id: 'perf-large-images',
155
+ severity: big.length >= 5 || total > 10 * 1024 * 1024 ? 'medium' : 'low',
156
+ area: 'performance',
157
+ title: `${big.length} image${big.length === 1 ? '' : 's'} over 500 KB in the app (${(total / 1024 / 1024).toFixed(1)} MB)`,
158
+ detail: `${big.slice(0, 3).map((b) => `${b.rel} (${Math.round(b.size / 1024)} KB)`).join(', ')}${big.length > 3 ? ', …' : ''}. They grow the download and take memory when decoded. Resize to the size shown on screen (2x/3x) and use WebP.`,
159
+ fix: { kind: 'performance', step: `Resize and convert the largest bundled images (${big.slice(0, 2).map((b) => `\`${b.rel}\``).join(', ')}) to WebP at the size shown on screen.` },
160
+ });
161
+ }
162
+ return findings;
163
+ }
package/src/plan.js CHANGED
@@ -66,6 +66,7 @@ const WEIGHTS = {
66
66
  'folly-flags': () => 0.25,
67
67
  'default-react-host': () => 0.25,
68
68
  crash: () => 1,
69
+ performance: () => 0.5,
69
70
  security: () => 1,
70
71
  'vuln-dep': (f) => (f.severity === 'critical' || f.severity === 'high' ? 1 : 0.25),
71
72
  };
@@ -526,6 +527,15 @@ export function buildPlan(result) {
526
527
  });
527
528
  }
528
529
 
530
+ const perf = byKind('performance');
531
+ if (perf.length) {
532
+ phases.push({
533
+ title: 'Speed up the app',
534
+ why: 'Static signs of jank and weight. Measure on a low-end Android device before and after: these are the usual suspects, not proof.',
535
+ steps: perf.map((p) => p.step),
536
+ });
537
+ }
538
+
529
539
  const jsBumps = byKind('bump-dep').filter((d) => !d.native && !movesWithExpo(d.name));
530
540
  if (jsBumps.length) {
531
541
  phases.push({
package/src/security.js CHANGED
@@ -584,6 +584,7 @@ export const MASVS_GROUPS = {
584
584
  NETWORK: 'Network traffic',
585
585
  PLATFORM: 'WebViews and platform interaction',
586
586
  CODE: 'Dependencies and build',
587
+ RESILIENCE: 'Reverse engineering',
587
588
  };
588
589
 
589
590
  export function masvsOf(id) {
@@ -593,5 +594,56 @@ export function masvsOf(id) {
593
594
  if (/^(webview-|android-exported)/.test(id)) return 'PLATFORM';
594
595
  if (/^firebase-/.test(id)) return 'AUTH';
595
596
  if (/^(vuln:|signing-|android-debuggable)/.test(id)) return 'CODE';
597
+ if (/^(sourcemap-in-app|easy-reverse-engineering)/.test(id)) return 'RESILIENCE';
596
598
  return null;
597
599
  }
600
+
601
+ // How easily the shipped app reads back as source (MASVS-RESILIENCE). React Native JavaScript is
602
+ // recoverable from any APK/IPA; Hermes bytecode and R8 only slow that down. The real defence is
603
+ // keeping secrets and trust decisions off the device, so this is advice, not an alarm.
604
+ export function reverseEngineering(root, project) {
605
+ const findings = [];
606
+ // Source maps packaged into the app give back the original code, names and comments.
607
+ const mapDirs = [path.join(root, 'android', 'app', 'src', 'main', 'assets'), path.join(root, 'ios')];
608
+ const maps = [];
609
+ const scan = (dir, depth) => {
610
+ let entries = [];
611
+ try {
612
+ entries = fs.readdirSync(dir, { withFileTypes: true });
613
+ } catch {
614
+ return;
615
+ }
616
+ for (const e of entries) {
617
+ if (e.isDirectory() && depth < 3 && !['Pods', 'build', 'DerivedData'].includes(e.name)) scan(path.join(dir, e.name), depth + 1);
618
+ else if (/\.(?:bundle|jsbundle|hbc)\.map$|^index\.android\.bundle\.map$|^main\.jsbundle\.map$/.test(e.name)) maps.push(path.relative(root, path.join(dir, e.name)));
619
+ }
620
+ };
621
+ for (const d of mapDirs) scan(d, 0);
622
+ if (maps.length) {
623
+ findings.push({
624
+ id: 'sourcemap-in-app',
625
+ severity: 'high',
626
+ area: 'security',
627
+ title: `A source map is packaged into the app (${maps[0]})`,
628
+ detail: 'Anyone who unzips the APK/IPA gets your original JavaScript with names and comments. Upload source maps to your crash reporter instead, and keep them out of the app folders. (OWASP MASVS-RESILIENCE)',
629
+ fix: { kind: 'security', step: `Remove \`${maps[0]}\` from the app sources (and from git), and upload source maps to the crash reporter instead.` },
630
+ });
631
+ }
632
+
633
+ const gradle = read(path.join(root, 'android', 'app', 'build.gradle')) || read(path.join(root, 'android', 'app', 'build.gradle.kts')) || '';
634
+ const props = read(path.join(root, 'android', 'gradle.properties')) || '';
635
+ const r8Off = gradle && (/enableProguardInReleaseBuilds\s*=\s*false/.test(gradle) || /release\s*\{[^}]*minifyEnabled\s*\(?\s*false/.test(gradle));
636
+ const hermesOff = /^\s*hermesEnabled\s*=\s*false/m.test(props) || /hermes_enabled\s*=>\s*false/.test(read(path.join(root, 'ios', 'Podfile')) || '');
637
+ const factors = [hermesOff && 'Hermes is off, so the JavaScript ships as readable text', r8Off && 'R8/ProGuard is off, so Java/Kotlin class and method names stay readable'].filter(Boolean);
638
+ if (factors.length && !project.managed) {
639
+ findings.push({
640
+ id: 'easy-reverse-engineering',
641
+ severity: 'low',
642
+ area: 'security',
643
+ title: 'The release build is easy to read back',
644
+ detail: `${factors.join('; ')}. Any React Native app can be unpacked, and obfuscation only slows that down, so never rely on it: keep secrets and checks that matter (prices, entitlements, admin flags) on the server. Turning these on is still cheap. (OWASP MASVS-RESILIENCE)`,
645
+ fix: { kind: 'security', step: `${hermesOff ? 'Turn on Hermes. ' : ''}${r8Off ? 'Set `enableProguardInReleaseBuilds = true` in `android/app/build.gradle` and test a release build (add keep rules for libraries that need them). ' : ''}Keep secrets and trust decisions on the server.` },
646
+ });
647
+ }
648
+ return findings;
649
+ }