Repository navigation
Harden public client secret boundaries - #8717
Git-on-my-level merged 9 commits into
Conversation
3b501da to
dca3450
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b501da7c3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| PUBLIC_INTERCOM_APP_ID="$INTERCOM_APP_ID" \ | ||
| PUBLIC_INTERCOM_IOS_API_KEY="$INTERCOM_IOS_API_KEY" \ | ||
| PUBLIC_INTERCOM_ANDROID_API_KEY="$INTERCOM_ANDROID_API_KEY" \ | ||
| ../scripts/create-public-client-env.sh .client.env |
There was a problem hiding this comment.
Preserve Android Intercom env generation
In the Android Codemagic workflows, this now only writes .client.env, but the Android Gradle build still reads app/.env to populate BuildConfig.INTERCOM_APP_ID and BuildConfig.INTERCOM_ANDROID_API_KEY (app/android/app/build.gradle:36 and :100-101). For internal/release Android builds those values become empty, so MyApp.kt skips Intercom SDK initialization; either keep emitting the legacy public .env entries for Gradle or update Gradle to read .client.env/PUBLIC_*.
Useful? React with 👍 / 👎.
| // Every field in this file is compiled into public client binaries. | ||
| // Do not add provider API keys, OAuth client secrets, service accounts, | ||
| // private keys, admin tokens, signing credentials, or backend-only secrets. | ||
| @Envied(allowOptionalFields: true, path: '.client.dev.env') |
There was a problem hiding this comment.
Generate the new dev env file during setup
The documented mobile setup still writes only .dev.env with the old names (app/setup.sh:142-144, with similar legacy setup scripts), but DevEnv now reads .client.dev.env. A fresh dev setup therefore generates null/default dev config, causing API calls to build URLs from a null Env.apiBaseUrl or crash where it is force-unwrapped; update the setup scripts to create .client.dev.env with the PUBLIC_* keys before switching this path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
18 issues found and verified against the latest diff
Confidence score: 2/5
- The highest risk is in
scripts/pre-commit, wherecheck-public-client-secrets.pyfailures do not block commits, andscripts/pre-pushcan missDockerfile.*changes; together, secret-boundary checks can be bypassed and sensitive values may slip into public artifacts — make both hooks fail closed and include Dockerfile variant patterns before merging. codemagic.yamlnow writes.client.envwhile Android build inputs inapp/android/app/build.gradleand dev setup paths inapp/lib/env/dev_env.dart/app/setup.shstill expect older.env/.dev.envconventions, which can leave required Intercom values unset and break dev or release builds — align file names and key mappings across scripts, Gradle, and Envied sources.- In
codemagic.yaml, the AAB scanner path uses**without enablingglobstar, so release pipelines can fail before publish even when the build itself succeeds — enableglobstaror expand artifact paths explicitly in the scanner step. scripts/scan-public-artifact-secrets.pyandscripts/check-public-client-secrets.pystill have enforcement gaps (DMGs treated as scanned without extraction, denied provider domains not enforced in app scans, and regex misses common quoted/path.envwrites), andapp/test/security/public_client_secret_boundary_test.dartcan pass on missing metadata; merging as-is leaves real policy blind spots — tighten these checks and fix the test assertion so regressions are caught.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/lib/env/dev_env.dart">
<violation number="1" location="app/lib/env/dev_env.dart:10">
P1: The Envied source path changed to `.client.dev.env`, but the developer setup scripts (e.g. `app/setup.sh`) still generate `.dev.env` with the old key names. A fresh dev setup will not produce `.client.dev.env`, so all Envied fields resolve to null defaults—`Env.apiBaseUrl` will be null at runtime, breaking API requests or crashing on force-unwrap. Update the setup scripts to create `.client.dev.env` with the `PUBLIC_*` keys.</violation>
</file>
<file name="codemagic.yaml">
<violation number="1" location="codemagic.yaml:95">
P1: The Android Gradle build reads `app/.env` to populate `BuildConfig.INTERCOM_APP_ID` and `BuildConfig.INTERCOM_ANDROID_API_KEY` (see `app/android/app/build.gradle`). This script now writes only to `.client.env`, so the Gradle-consumed values will be empty at build time—Intercom SDK initialization will be silently skipped on Android release builds. Either emit a legacy `.env` with the public Intercom entries for Gradle, or update `build.gradle` to read from `.client.env`/`PUBLIC_*` keys.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| PUBLIC_INTERCOM_APP_ID="$INTERCOM_APP_ID" \ | ||
| PUBLIC_INTERCOM_IOS_API_KEY="$INTERCOM_IOS_API_KEY" \ | ||
| PUBLIC_INTERCOM_ANDROID_API_KEY="$INTERCOM_ANDROID_API_KEY" \ | ||
| ../scripts/create-public-client-env.sh .client.env |
There was a problem hiding this comment.
P1: The Android Gradle build reads app/.env to populate BuildConfig.INTERCOM_APP_ID and BuildConfig.INTERCOM_ANDROID_API_KEY (see app/android/app/build.gradle). This script now writes only to .client.env, so the Gradle-consumed values will be empty at build time—Intercom SDK initialization will be silently skipped on Android release builds. Either emit a legacy .env with the public Intercom entries for Gradle, or update build.gradle to read from .client.env/PUBLIC_* keys.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At codemagic.yaml, line 95:
<comment>The Android Gradle build reads `app/.env` to populate `BuildConfig.INTERCOM_APP_ID` and `BuildConfig.INTERCOM_ANDROID_API_KEY` (see `app/android/app/build.gradle`). This script now writes only to `.client.env`, so the Gradle-consumed values will be empty at build time—Intercom SDK initialization will be silently skipped on Android release builds. Either emit a legacy `.env` with the public Intercom entries for Gradle, or update `build.gradle` to read from `.client.env`/`PUBLIC_*` keys.</comment>
<file context>
@@ -80,20 +80,19 @@ workflows:
+ PUBLIC_INTERCOM_APP_ID="$INTERCOM_APP_ID" \
+ PUBLIC_INTERCOM_IOS_API_KEY="$INTERCOM_IOS_API_KEY" \
+ PUBLIC_INTERCOM_ANDROID_API_KEY="$INTERCOM_ANDROID_API_KEY" \
+ ../scripts/create-public-client-env.sh .client.env
- name: Set up Google Service Info
</file context>
| // Every field in this file is compiled into public client binaries. | ||
| // Do not add provider API keys, OAuth client secrets, service accounts, | ||
| // private keys, admin tokens, signing credentials, or backend-only secrets. | ||
| @Envied(allowOptionalFields: true, path: '.client.dev.env') |
There was a problem hiding this comment.
P1: The Envied source path changed to .client.dev.env, but the developer setup scripts (e.g. app/setup.sh) still generate .dev.env with the old key names. A fresh dev setup will not produce .client.dev.env, so all Envied fields resolve to null defaults—Env.apiBaseUrl will be null at runtime, breaking API requests or crashing on force-unwrap. Update the setup scripts to create .client.dev.env with the PUBLIC_* keys.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At app/lib/env/dev_env.dart, line 10:
<comment>The Envied source path changed to `.client.dev.env`, but the developer setup scripts (e.g. `app/setup.sh`) still generate `.dev.env` with the old key names. A fresh dev setup will not produce `.client.dev.env`, so all Envied fields resolve to null defaults—`Env.apiBaseUrl` will be null at runtime, breaking API requests or crashing on force-unwrap. Update the setup scripts to create `.client.dev.env` with the `PUBLIC_*` keys.</comment>
<file context>
@@ -4,55 +4,50 @@ import 'env.dart';
+// Every field in this file is compiled into public client binaries.
+// Do not add provider API keys, OAuth client secrets, service accounts,
+// private keys, admin tokens, signing credentials, or backend-only secrets.
+@Envied(allowOptionalFields: true, path: '.client.dev.env')
final class DevEnv implements EnvFields {
DevEnv();
</file context>
There was a problem hiding this comment.
12 issues found across 22 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/lib/env/dev_env.dart">
<violation number="1" location="app/lib/env/dev_env.dart:10">
P1: The Envied source path changed to `.client.dev.env`, but the developer setup scripts (e.g. `app/setup.sh`) still generate `.dev.env` with the old key names. A fresh dev setup will not produce `.client.dev.env`, so all Envied fields resolve to null defaults—`Env.apiBaseUrl` will be null at runtime, breaking API requests or crashing on force-unwrap. Update the setup scripts to create `.client.dev.env` with the `PUBLIC_*` keys.</violation>
</file>
<file name="codemagic.yaml">
<violation number="1" location="codemagic.yaml:95">
P1: The Android Gradle build reads `app/.env` to populate `BuildConfig.INTERCOM_APP_ID` and `BuildConfig.INTERCOM_ANDROID_API_KEY` (see `app/android/app/build.gradle`). This script now writes only to `.client.env`, so the Gradle-consumed values will be empty at build time—Intercom SDK initialization will be silently skipped on Android release builds. Either emit a legacy `.env` with the public Intercom entries for Gradle, or update `build.gradle` to read from `.client.env`/`PUBLIC_*` keys.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
6 issues found across 19 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/lib/env/dev_env.dart">
<violation number="1" location="app/lib/env/dev_env.dart:10">
P1: The Envied source path changed to `.client.dev.env`, but the developer setup scripts (e.g. `app/setup.sh`) still generate `.dev.env` with the old key names. A fresh dev setup will not produce `.client.dev.env`, so all Envied fields resolve to null defaults—`Env.apiBaseUrl` will be null at runtime, breaking API requests or crashing on force-unwrap. Update the setup scripts to create `.client.dev.env` with the `PUBLIC_*` keys.</violation>
</file>
<file name="codemagic.yaml">
<violation number="1" location="codemagic.yaml:95">
P1: The Android Gradle build reads `app/.env` to populate `BuildConfig.INTERCOM_APP_ID` and `BuildConfig.INTERCOM_ANDROID_API_KEY` (see `app/android/app/build.gradle`). This script now writes only to `.client.env`, so the Gradle-consumed values will be empty at build time—Intercom SDK initialization will be silently skipped on Android release builds. Either emit a legacy `.env` with the public Intercom entries for Gradle, or update `build.gradle` to read from `.client.env`/`PUBLIC_*` keys.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
1 issue found across 6 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/lib/env/dev_env.dart">
<violation number="1" location="app/lib/env/dev_env.dart:10">
P1: The Envied source path changed to `.client.dev.env`, but the developer setup scripts (e.g. `app/setup.sh`) still generate `.dev.env` with the old key names. A fresh dev setup will not produce `.client.dev.env`, so all Envied fields resolve to null defaults—`Env.apiBaseUrl` will be null at runtime, breaking API requests or crashing on force-unwrap. Update the setup scripts to create `.client.dev.env` with the `PUBLIC_*` keys.</violation>
</file>
<file name="codemagic.yaml">
<violation number="1" location="codemagic.yaml:95">
P1: The Android Gradle build reads `app/.env` to populate `BuildConfig.INTERCOM_APP_ID` and `BuildConfig.INTERCOM_ANDROID_API_KEY` (see `app/android/app/build.gradle`). This script now writes only to `.client.env`, so the Gradle-consumed values will be empty at build time—Intercom SDK initialization will be silently skipped on Android release builds. Either emit a legacy `.env` with the public Intercom entries for Gradle, or update `build.gradle` to read from `.client.env`/`PUBLIC_*` keys.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
2 issues found across 8 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/lib/env/dev_env.dart">
<violation number="1" location="app/lib/env/dev_env.dart:10">
P1: The Envied source path changed to `.client.dev.env`, but the developer setup scripts (e.g. `app/setup.sh`) still generate `.dev.env` with the old key names. A fresh dev setup will not produce `.client.dev.env`, so all Envied fields resolve to null defaults—`Env.apiBaseUrl` will be null at runtime, breaking API requests or crashing on force-unwrap. Update the setup scripts to create `.client.dev.env` with the `PUBLIC_*` keys.</violation>
</file>
<file name="codemagic.yaml">
<violation number="1" location="codemagic.yaml:95">
P1: The Android Gradle build reads `app/.env` to populate `BuildConfig.INTERCOM_APP_ID` and `BuildConfig.INTERCOM_ANDROID_API_KEY` (see `app/android/app/build.gradle`). This script now writes only to `.client.env`, so the Gradle-consumed values will be empty at build time—Intercom SDK initialization will be silently skipped on Android release builds. Either emit a legacy `.env` with the public Intercom entries for Gradle, or update `build.gradle` to read from `.client.env`/`PUBLIC_*` keys.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="app/lib/env/dev_env.dart">
<violation number="1" location="app/lib/env/dev_env.dart:10">
P1: The Envied source path changed to `.client.dev.env`, but the developer setup scripts (e.g. `app/setup.sh`) still generate `.dev.env` with the old key names. A fresh dev setup will not produce `.client.dev.env`, so all Envied fields resolve to null defaults—`Env.apiBaseUrl` will be null at runtime, breaking API requests or crashing on force-unwrap. Update the setup scripts to create `.client.dev.env` with the `PUBLIC_*` keys.</violation>
</file>
<file name="codemagic.yaml">
<violation number="1" location="codemagic.yaml:95">
P1: The Android Gradle build reads `app/.env` to populate `BuildConfig.INTERCOM_APP_ID` and `BuildConfig.INTERCOM_ANDROID_API_KEY` (see `app/android/app/build.gradle`). This script now writes only to `.client.env`, so the Gradle-consumed values will be empty at build time—Intercom SDK initialization will be silently skipped on Android release builds. Either emit a legacy `.env` with the public Intercom entries for Gradle, or update `build.gradle` to read from `.client.env`/`PUBLIC_*` keys.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
## Summary Closes #8726. This audits the post-#8717 public release secret boundary and fills the remaining public-safe scanner gaps: - adds release workflow/log hygiene checks for dangerous public env writes and `set -x` blocks that touch server-only env refs - broadens public Dockerfile secret-baking coverage across `web/**`, `plugins/**`, `mcp/**`, and `desktop/**` - allowlists existing public web build args used by admin/app public images - adds a docs audit page with what #8717 covered, what this PR adds, and what remains private-maintainer evidence - adds fake-sentinel scanner tests, including zipped build-log leakage detection ## Secret-safety note No production credentials were read, printed, stored, or committed. Tests use fake sentinel values only. No release, deploy, provider, or artifact publication actions were run. ## Validation - `python3 scripts/test-public-secret-scanners.py` -> OK, 4 tests - `python3 scripts/check-public-client-secrets.py` -> passed - `git diff --check` - `python3 -m py_compile scripts/check-public-client-secrets.py scripts/scan-public-artifact-secrets.py scripts/test-public-secret-scanners.py` - `black --check --line-length 120 --skip-string-normalization scripts/check-public-client-secrets.py scripts/test-public-secret-scanners.py` - pre-push hook on push to `origin/codex/8726-release-secret-hygiene` -> passed, including OpenAPI up-to-date check <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/8730?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
## Why The latest TestFlight builds (**1.0.542+969 / +970**) shipped broken. Root causes, both from the public-client secret-boundary hardening (#8716, #8717, #8733, #8741): 1. **Null API base URL → crash on launch.** Those PRs renamed every app env var to a `PUBLIC_` prefix and moved Envied's source from `.env` → `.client.env`. The Codemagic dashboard still defines the **old** names, so the `PUBLIC_*` exports resolved empty, `create-public-client-env.sh` skipped them, and Envied baked `null` into prod. `Env.apiBaseUrl!` then force-unwrapped to a crash. 2. **`flutter build ipa` failure.** The post-build artifact scanner flagged Firebase/SDK constant strings (`ERROR_INVALID_CREDENTIAL`, `PROJECT_TOKEN`, …) inside the compiled `BatteryWidget.appex` Mach-O binary as "server-only tokens" — false positives. ## What this does - **Restores `codemagic.yaml` + `app/lib/env/**` to the last-good (1.0.533) state** — byte-identical, verified 0-diff. The prod build again reads the old var names that are still in the Codemagic dashboard. - **Reverts the coupled secret-scanner apparatus as one unit** (it's cross-wired through `lint.yml`, the git hooks, and the backend registry, so half-reverting would fail CI): scanner scripts, `client_env_policy.yaml`, the boundary test, the backend secret-consumer registry, and the `lint.yml`/`pre-commit`/`pre-push` enforcement. - Also restores `openai.dart`, the STT provider/polling code, app setup scripts, and env tests to baseline. ## What is deliberately preserved (independent web hardening) Not reverted — these removed baked secrets from the **web** images and are unrelated to the mobile break: - `.github/workflows/gcp_apps_js.yml`, `gcp_frontend.yml`, `gcp_personas.yml` (baked-secret removal from Docker build args + env-choice/SHA tagging) - `web/frontend/**`, `web/personas-open-source/**`, `plugins/apps-js/**` ## Verification - `codemagic.yaml` + `app/lib/env` diff vs the pre-hardening baseline: **0 lines**; no `PUBLIC_API_BASE_URL` left in `codemagic.yaml`. - No dangling references to any deleted script anywhere in the tree. - `dart analyze` on the reverted app code: no errors. - `flutter test` (env + capture_provider): **75/75 pass**. ## Note This returns the mobile client to its long-standing pre-1.0.542 secret posture (OpenAI/Google client secrets baked into the binary again). That is the status quo that shipped in 1.0.533 and every prior release — not a new exposure — but the underlying hardening should be re-attempted later by adding the `PUBLIC_*` vars to Codemagic first, then re-landing, rather than renaming under a live dashboard. <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/8772?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
Builds 1.0.542+969/970 shipped broken: the secret-boundary PRs (BasedHardware#8716, BasedHardware#8717, BasedHardware#8733, BasedHardware#8741) renamed every app env var to a PUBLIC_ prefix and moved Envied's source to .client.env, but the Codemagic dashboard still defines the old names. The PUBLIC_* exports resolved empty, create-public-client-env.sh skipped them, and Envied baked null into prod — so Env.apiBaseUrl! force-unwrapped to a crash on launch. The post-build artifact scanner also false-positived on Firebase/SDK constant strings (ERROR_INVALID_CREDENTIAL, PROJECT_TOKEN) inside the compiled BatteryWidget.appex, failing 'flutter build ipa'. Restores codemagic.yaml and app/lib/env to the last-good (1.0.533) state so the prod build works with the existing dashboard vars, and reverts the coupled secret-scanner apparatus (scanner scripts, client_env_policy, boundary test, backend secret-consumer registry, and the lint.yml/pre-commit/pre-push enforcement) as one unit. Preserves the independent web hardening: the gcp_apps_js/frontend/personas workflows keep their baked-secret removal + env-choice/SHA-tagging, and web/frontend, web/personas-open-source, and plugins/apps-js are untouched.
Summary
Verification
python3 scripts/check-public-client-secrets.pypython3 -m py_compile scripts/check-public-client-secrets.py scripts/scan-public-artifact-secrets.pybash -n scripts/create-public-client-env.sh scripts/pre-commit scripts/pre-pushpython3 -m black --line-length 120 --skip-string-normalization scripts/check-public-client-secrets.py scripts/scan-public-artifact-secrets.pydart format --line-length 120 app/lib/env/prod_env.dart app/lib/env/dev_env.dart app/lib/env/env.dart app/test/providers/capture_provider_test.dart app/test/unit/env_test.dart app/test/unit/env_empty_staging_test.dart app/test/unit/env_staging_test.dart app/test/security/public_client_secret_boundary_test.dartpython3 scripts/scan-public-artifact-secrets.py --helpOPENAI_API_KEYandFOO_SECRETgo run github.com/rhysd/actionlint/cmd/[email protected] -shellcheck '' .github/workflows/lint.yml .github/workflows/gcp_apps_js.yml .github/workflows/gcp_frontend.yml .github/workflows/gcp_personas.yml.github/scripts/run-pre-push.sh originNotes
app/test.sh test/security/public_client_secret_boundary_test.dartcould not run locally becauseflutteris not installed/on PATH in this environment.--no-verifyafter.github/scripts/run-pre-push.sh originpassed; the normal push hook compared against stalefork/main(d7970556) instead of the real upstream base (2483bb2) and selected unrelated pre-existing backend async-blocker findings.