Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(mobile): Require secure UUIDs and preserve CodeQL baseline

Chadpiha5f3006c8d79d
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index ae7261589..f0e7c2868 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -83,8 +83,11 @@ and App Store submissions remain separate release checks. Fork PR jobs receive n
Expo or Apple credentials and cannot deploy.
Repository maintainers should require **Desktop CI**, **Mobile CI**, **CodeQL CI**,
-and **lockfile-lint** in the GitHub ruleset, replacing individual build/matrix checks
-and the previous CodeQL check. The lockfile job is skipped successfully for mobile
+and **lockfile-lint** in the GitHub ruleset, replacing individual build/matrix checks.
+Also require GitHub's **CodeQL** code-scanning results check (or a CodeQL code-scanning
+merge-protection rule). **CodeQL CI** only confirms that the selected scans completed;
+it does not enforce alert severity. Retain the security-results check to block new
+high/critical findings. The lockfile job is skipped successfully for mobile
changes, whose lockfile is covered by Mobile CI. Require review before merging,
including explicit review of workflow and dependency changes, and enable approval
for workflows from outside contributors. Ruleset settings are managed on GitHub;
diff --git a/.github/scripts/ci-scope.cjs b/.github/scripts/ci-scope.cjs
index 46a1a6014..b74f984f6 100644
--- a/.github/scripts/ci-scope.cjs
+++ b/.github/scripts/ci-scope.cjs
@@ -70,11 +70,9 @@ function main() {
console.warn("Unable to determine changed paths; running both applications' checks.");
}
}
- const codeqlScopes = ["desktop", "mobile"].filter((name) => scope[name]);
- const outputs = { ...scope, "codeql-scopes": JSON.stringify(codeqlScopes) };
appendFileSync(
process.env.GITHUB_OUTPUT,
- Object.entries(outputs)
+ Object.entries(scope)
.map(([key, value]) => `${key}=${value}\n`)
.join("")
);
diff --git a/.github/workflows/ci-changes.yml b/.github/workflows/ci-changes.yml
index 8d17d2f79..69e3ecaad 100644
--- a/.github/workflows/ci-changes.yml
+++ b/.github/workflows/ci-changes.yml
@@ -9,8 +9,6 @@ on:
value: ${{ jobs.changes.outputs.mobile }}
build:
value: ${{ jobs.changes.outputs.build }}
- codeql-scopes:
- value: ${{ jobs.changes.outputs.codeql-scopes }}
permissions:
contents: read
@@ -23,7 +21,6 @@ jobs:
desktop: ${{ steps.scope.outputs.desktop }}
mobile: ${{ steps.scope.outputs.mobile }}
build: ${{ steps.scope.outputs.build }}
- codeql-scopes: ${{ steps.scope.outputs.codeql-scopes }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
index 61abc42fc..87d2cd6a1 100644
--- a/.github/workflows/codeql.yml
+++ b/.github/workflows/codeql.yml
@@ -20,9 +20,9 @@ jobs:
uses: ./.github/workflows/ci-changes.yml
analyze:
- name: Analyze (${{ matrix.scope }})
+ name: Analyze (desktop)
needs: changes
- if: needs.changes.outputs.desktop == 'true' || needs.changes.outputs.mobile == 'true'
+ if: needs.changes.outputs.desktop == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
@@ -31,7 +31,35 @@ jobs:
strategy:
fail-fast: false
matrix:
- scope: ${{ fromJSON(needs.changes.outputs.codeql-scopes) }}
+ # Preserve the main-branch analysis identity for PR comparisons.
+ language: [javascript-typescript]
+ steps:
+ - name: Checkout
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
+ with:
+ persist-credentials: false
+
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@ed1a0fa18ac745d017ca370dd4ef08bba3b4f504 # v3
+ with:
+ languages: ${{ matrix.language }}
+ build-mode: none
+ config: '{"paths-ignore":["apps/mobile/**"]}'
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@ed1a0fa18ac745d017ca370dd4ef08bba3b4f504 # v3
+ with:
+ category: /language:${{ matrix.language }}
+
+ analyze-mobile:
+ name: Analyze (mobile)
+ needs: changes
+ if: needs.changes.outputs.mobile == 'true'
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ permissions:
+ security-events: write
+ contents: read
steps:
- name: Checkout
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
@@ -43,16 +71,16 @@ jobs:
with:
languages: javascript-typescript
build-mode: none
- config: ${{ matrix.scope == 'mobile' && '{"paths":["apps/mobile"]}' || '{"paths-ignore":["apps/mobile/**"]}' }}
+ config: '{"paths":["apps/mobile"]}'
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@ed1a0fa18ac745d017ca370dd4ef08bba3b4f504 # v3
with:
- category: /language:javascript-typescript/${{ matrix.scope }}
+ category: /language:javascript-typescript/mobile
codeql-status:
name: CodeQL CI
- needs: [changes, analyze]
+ needs: [changes, analyze, analyze-mobile]
if: always()
runs-on: ubuntu-latest
timeout-minutes: 5
@@ -63,9 +91,13 @@ jobs:
CHANGES_RESULT: ${{ needs.changes.result }}
DESKTOP: ${{ needs.changes.outputs.desktop }}
MOBILE: ${{ needs.changes.outputs.mobile }}
- ANALYZE_RESULT: ${{ needs.analyze.result }}
+ DESKTOP_RESULT: ${{ needs.analyze.result }}
+ MOBILE_RESULT: ${{ needs.analyze-mobile.result }}
run: |
test "$CHANGES_RESULT" = success
- if [ "$DESKTOP" = true ] || [ "$MOBILE" = true ]; then
- test "$ANALYZE_RESULT" = success
+ if [ "$DESKTOP" = true ]; then
+ test "$DESKTOP_RESULT" = success
+ fi
+ if [ "$MOBILE" = true ]; then
+ test "$MOBILE_RESULT" = success
fi
diff --git a/apps/mobile/jest.config.js b/apps/mobile/jest.config.js
index 3994f5da5..47fcd3fff 100644
--- a/apps/mobile/jest.config.js
+++ b/apps/mobile/jest.config.js
@@ -1,6 +1,7 @@
/** @type {import('jest').Config} */
module.exports = {
preset: 'jest-expo',
+ setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
diff --git a/apps/mobile/jest.setup.js b/apps/mobile/jest.setup.js
new file mode 100644
index 000000000..272a8e592
--- /dev/null
+++ b/apps/mobile/jest.setup.js
@@ -0,0 +1,7 @@
+/* global jest */
+// jest-expo does not implement the native UUID generator. Keep the replacement
+// in the test environment so production always requires Expo's secure generator.
+jest.mock('expo-crypto', () => ({
+ ...jest.requireActual('expo-crypto'),
+ randomUUID: jest.requireActual('node:crypto').randomUUID,
+}));
diff --git a/apps/mobile/src/lib/__tests__/uuid.test.ts b/apps/mobile/src/lib/__tests__/uuid.test.ts
index 6719214c4..aac43cd3b 100644
--- a/apps/mobile/src/lib/__tests__/uuid.test.ts
+++ b/apps/mobile/src/lib/__tests__/uuid.test.ts
@@ -1,37 +1,59 @@
describe('randomUUID', () => {
- afterEach(() => {
+ beforeEach(() => {
jest.resetModules();
+ });
+
+ afterEach(() => {
+ jest.restoreAllMocks();
jest.dontMock('expo-crypto');
});
- it('falls back to a locally-generated id when the native module returns falsy (the real jest-expo condition today)', () => {
- // No mocking here: this exercises the actual environment gap this
- // fallback exists for — expo-crypto's native module isn't wired up
- // under jest-expo, so Crypto.randomUUID() resolves to undefined.
+ it('returns the UUID produced by Expo Crypto', () => {
+ const nativeUUID = 'ac028740-f771-4e64-bde7-f0c334e4d653';
+ jest.doMock('expo-crypto', () => ({ randomUUID: () => nativeUUID }));
const { randomUUID } = require('../uuid') as typeof import('../uuid');
- const id = randomUUID();
-
- expect(typeof id).toBe('string');
- expect(id.length).toBeGreaterThan(10);
- // v4-shaped: 8-4-4-4-12 hex groups, version nibble 4, variant nibble 8-b.
- expect(id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
+ expect(randomUUID()).toBe(nativeUUID);
});
- it('produces different ids across calls', () => {
+ it.each([undefined, null, ''])('fails closed when Expo Crypto returns %p', (value) => {
+ jest.doMock('expo-crypto', () => ({ randomUUID: () => value }));
const { randomUUID } = require('../uuid') as typeof import('../uuid');
-
- const ids = new Set(Array.from({ length: 20 }, () => randomUUID()));
-
- expect(ids.size).toBe(20);
+ const insecureRandom = jest.spyOn(Math, 'random');
+
+ let failure: unknown;
+ try {
+ randomUUID();
+ } catch (error) {
+ failure = error;
+ }
+ const insecureCalls = insecureRandom.mock.calls.length;
+ insecureRandom.mockRestore();
+
+ expect(failure).toEqual(new Error('Secure UUID generation is unavailable'));
+ expect(insecureCalls).toBe(0);
});
- it('uses the native value when expo-crypto actually returns one', () => {
- jest.resetModules();
- jest.doMock('expo-crypto', () => ({ randomUUID: () => 'native-uuid-value' }));
-
+ it('propagates native failures without falling back to insecure randomness', () => {
+ const nativeError = new Error('Native crypto unavailable');
+ jest.doMock('expo-crypto', () => ({
+ randomUUID: () => {
+ throw nativeError;
+ },
+ }));
const { randomUUID } = require('../uuid') as typeof import('../uuid');
-
- expect(randomUUID()).toBe('native-uuid-value');
+ const insecureRandom = jest.spyOn(Math, 'random');
+
+ let failure: unknown;
+ try {
+ randomUUID();
+ } catch (error) {
+ failure = error;
+ }
+ const insecureCalls = insecureRandom.mock.calls.length;
+ insecureRandom.mockRestore();
+
+ expect(failure).toBe(nativeError);
+ expect(insecureCalls).toBe(0);
});
});
diff --git a/apps/mobile/src/lib/uuid.ts b/apps/mobile/src/lib/uuid.ts
index 77a8465de..430c7b1f3 100644
--- a/apps/mobile/src/lib/uuid.ts
+++ b/apps/mobile/src/lib/uuid.ts
@@ -1,19 +1,9 @@
import * as Crypto from 'expo-crypto';
-// Falls back to a Math.random()-based v4-shaped id when the native module
-// doesn't produce one (observed under jest-expo, where the ExpoCrypto native
-// module isn't wired up and Crypto.randomUUID() resolves to undefined — see
-// migrate.test.ts). These ids are device-local only (client_*_id columns),
-// never sent to the server as security material, so this fallback's weaker
-// entropy is an acceptable tradeoff for "never throws, always unique enough".
-function fallbackUUID(): string {
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (char) => {
- const random = (Math.random() * 16) | 0;
- const value = char === 'x' ? random : (random & 0x3) | 0x8;
- return value.toString(16);
- });
-}
-
export function randomUUID(): string {
- return Crypto.randomUUID() || fallbackUUID();
+ const uuid = Crypto.randomUUID();
+ if (!uuid) {
+ throw new Error('Secure UUID generation is unavailable');
+ }
+ return uuid;
}