返回提示词目录第 1386 页

排查并修复客户端密钥泄露

检查网页与移动应用构建产物,区分公开配置和敏感密钥,修复暴露并列出轮换及防护措施。

完整提示词

<context>
Anything in a client bundle or app package is public: minification and obfuscation do not hide strings, and app packages can be unpacked in minutes. Build tools copy environment variables into the bundle by prefix (`NEXT_PUBLIC_`, `VITE_`, `REACT_APP_`, `EXPO_PUBLIC_`, `NUXT_PUBLIC_`, SvelteKit's public env), so a secret given one of those prefixes "to make it work" ships to every user. Other routes: config files imported by client code, source maps published to production that contain original source and comments, and native config files or string resources in mobile apps. Not every key is a secret, though: Firebase web config, Stripe publishable keys, Supabase anon keys and Maps browser keys are designed to be public and are protected by rules, restrictions or server-side checks. The real job is telling the two apart, moving true secrets (Stripe secret keys, OpenAI or other LLM API keys, database URLs, service role keys, signing secrets) behind a server endpoint, and restricting the public ones.
</context>

<task>
Find secrets exposed to clients in {{app}}.

1. Read the build configuration and list every environment variable exposed to the client by prefix or explicit `define`/`env` config, and every import of config or secret files from client code.
2. Build the app for production locally and search the output (`dist/`, `.next/static`, `build/`, the APK or IPA contents if the project builds one) for key patterns, the names of known secret variables, and high-entropy strings. Check whether source maps are emitted and published.
3. For mobile, check native config (`Info.plist`, `AndroidManifest.xml`, `strings.xml`, `gradle.properties`, embedded JSON) and hard-coded strings in code.
4. Classify each value: public by design (and whether its restrictions are set, such as referrer, bundle id or security rules), or secret. Never print values; show variable name, file and the first few characters only if needed to identify the type.
5. For each secret, move the call that needs it to a server endpoint, edge function or backend proxy that authenticates the user and rate limits, and remove the variable from the client build.
6. List which secrets were ever shipped in a release and therefore must be rotated, with the provider and the order to do it.
7. Add prevention: a CI check that fails when a secret pattern appears in build output, lint or naming rules so server-only variables cannot get a public prefix, and hidden or unpublished source maps.
8. Rebuild and search the output again to confirm the secrets are gone; run the tests.
</task>

<constraints>
- Never print secret values in the report, logs or commits.
- Do not rotate keys yourself; give the steps and note what breaks during rotation.
- Do not mark a public-by-design key as safe without checking its restrictions or rules.
{{> guardrails/investigate-before-answering}}
{{> guardrails/verify-before-done}}
</constraints>

<output_format>
## Exposed values
Table: variable or string, where it ships (bundle, source map, app package), file.
## Classification
Table: value, public by design or secret, restrictions in place, action.
## Changes
One line per file: `path`, what changed.
## Rotation needed
Ordered list of secrets to rotate, provider, and impact.
## Prevention
The CI check and rules added.
## Verification
Build output searched again and the actual result.
</output_format>

可替换内容

  • {{app}}
  • {{> guardrails/investigate-before-answering}}
  • {{> guardrails/verify-before-done}}

分类与标签

编程开发、密钥泄露排查、客户端安全、构建产物审计、持续集成检测

前往 AI 图片创作