Skip to content

t4939: Add env-var-not-argument pattern to secret handling rules#4941

Merged
marcusquinn merged 1 commit intomainfrom
chore/t4939-env-var-secret-pattern
Mar 15, 2026
Merged

t4939: Add env-var-not-argument pattern to secret handling rules#4941
marcusquinn merged 1 commit intomainfrom
chore/t4939-env-var-secret-pattern

Conversation

@alex-solovyev
Copy link
Collaborator

@alex-solovyev alex-solovyev commented Mar 15, 2026

Summary

  • Adds explicit "env var, not argument" rule (section 8.2) to prompts/build.txt secret handling — when a subprocess needs a secret, pass it as an environment variable, never as a command argument
  • Adds post-execution secret detection guidance (section 8.3) — assess command output for leaked credentials after failures
  • Updates opsec.md, gopass.md, and cloudron.md with cross-references to the new pattern

Why

Command arguments appear in error messages, ps output, and logs. An incident during a migration session showed that even "safe" commands (DB inserts) can echo secrets back when they fail. The existing rule ("don't expose secrets") was too abstract — agents assessed commands as safe based on intent, not on what error paths could reveal. This makes the safe pattern explicit with concrete SAFE/UNSAFE examples.

Changes

File Change
.agents/prompts/build.txt New sections 8.2 (env var not argument) and 8.3 (post-execution detection) with incident context, safe/unsafe patterns, and fallback guidance
.agents/tools/security/opsec.md Added env-var-not-argument bullet to Secret-Safe Command Policy
.agents/tools/credentials/gopass.md Added env-var-not-argument paragraph to Agent Instructions + new prohibited command entry
.agents/services/hosting/cloudron.md Added cross-reference to section 8.2 on existing -p$(cat ...) security note

Closes #4939

Summary by CodeRabbit

  • Documentation
    • Enhanced security guidelines clarifying best practices for handling secrets in subprocess operations.
    • Added detailed guidance recommending environment variables over command-line arguments for credential passing.
    • Expanded examples of safe and unsafe patterns for secret handling across multiple documentation sections.

When a subprocess needs a secret value, pass it as an environment
variable, never as a command argument. Command arguments appear in
error messages, ps output, and logs -- even when the command's intent
is safe. This was learned from an incident where wp db query echoed
a secret in its error output.

Adds section 8.2 (prevention) and 8.3 (post-execution detection) to
prompts/build.txt. Updates opsec.md, gopass.md, and cloudron.md with
cross-references to the new pattern.

Closes #4939
@github-actions github-actions bot added the enhancement Auto-created from TODO.md tag label Mar 15, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the system's secret handling policies by introducing explicit guidelines to prevent credential exposure. It addresses a critical vulnerability where secrets passed as command arguments can leak into logs, ps output, or error messages, even for seemingly safe operations. The changes aim to make the secure pattern of using environment variables for secrets explicit, thereby improving overall operational security and reducing the risk of accidental credential compromise.

Highlights

  • New Secret Handling Rule: Introduced an explicit "env var, not argument" rule (section 8.2) in prompts/build.txt to ensure secrets are passed as environment variables, not command arguments, to subprocesses.
  • Post-Execution Secret Detection: Added guidance (section 8.3) for post-execution secret detection, advising assessment of command output for leaked credentials, especially after failures.
  • Documentation Updates: Updated opsec.md, gopass.md, and cloudron.md to include cross-references to the new secret handling patterns and policies.
Changelog
  • .agents/prompts/build.txt
    • New sections 8.2 (env var not argument) and 8.3 (post-execution detection) with incident context, safe/unsafe patterns, and fallback guidance
  • .agents/services/hosting/cloudron.md
    • Added cross-reference to section 8.2 on existing -p$(cat ...) security note
  • .agents/tools/credentials/gopass.md
    • Added env-var-not-argument paragraph to Agent Instructions + new prohibited command entry
  • .agents/tools/security/opsec.md
    • Added env-var-not-argument bullet to Secret-Safe Command Policy
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

Security guidelines enhanced across documentation to formalize secret handling in subprocesses: secrets must pass via environment variables, not command-line arguments. Safe/unsafe patterns documented with concrete examples. Post-execution secret detection added to flag contaminated output when credentials passed as arguments fail.

Changes

Cohort / File(s) Summary
Core Security Guidelines
.agents/prompts/build.txt
Introduces formal rule for subprocess secrets: always use environment variables, never command arguments. Adds safe/unsafe pattern examples in section 8.2, post-execution secret detection logic in 8.3 to withhold contaminated output on command failure.
Tool & Service Documentation
.agents/tools/credentials/gopass.md, .agents/tools/security/opsec.md, .agents/services/hosting/cloudron.md
References and reinforces environment variable pattern for secrets. Documents prohibited command pattern (cmd "$SECRET"), notes visibility in ps/logs/error messages, links to detailed rules in build.txt section 8.2.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

Secrets whisper through the environment's veil,
Never shouted in arguments where error logs prevail,
ps cannot see them, nor error output's cry,
Safe in getenv() they securely lie,
🔐✨ When in doubt, use variables—not argv!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding an explicit 'env-var-not-argument' pattern to secret handling rules, which is the core of all modifications across multiple documentation files.
Linked Issues check ✅ Passed The PR comprehensively addresses both layers of #4939: Layer 1 (prevention) is fully implemented with explicit env-var-not-argument rules, SAFE/UNSAFE examples, and post-execution detection guidance across all files; Layer 2 (detection) is partially implemented with post-execution guidance in build.txt section 8.3.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the requirements of #4939: documentation updates to four files reinforcing the env-var-not-argument pattern, post-execution detection guidance, and cross-references to the new section 8.2; no unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/t4939-env-var-secret-pattern
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 362 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sun Mar 15 17:42:55 UTC 2026: Code review monitoring started
Sun Mar 15 17:42:56 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 362

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 362
  • VULNERABILITIES: 0

Generated on: Sun Mar 15 17:42:58 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

@marcusquinn marcusquinn merged commit 2ea4f89 into main Mar 15, 2026
25 of 26 checks passed
@marcusquinn marcusquinn deleted the chore/t4939-env-var-secret-pattern branch March 15, 2026 17:45
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an important security rule about not passing secrets as command-line arguments, instead favoring environment variables. The changes are well-motivated and clearly explained across several documentation files. The new rules in prompts/build.txt are comprehensive, with good examples. I've added one suggestion to make the fallback pattern for secret handling (using temporary files) even more robust by mentioning specific tools like mktemp and trap.

- SAFE: `aidevops secret NAME -- cmd` — injects as env var with automatic output redaction
- SAFE: `SSH_AUTH_SOCK=... ssh ...` — env-based auth, no secret in argv
- The subprocess must read the value from its environment (`getenv()` in C/PHP, `process.env` in Node, `os.environ` in Python, `ENV[]` in Ruby), not from `$1`/`argv`.
- When the target program only accepts secrets as arguments (no env var support), write the secret to a temporary file (mode 0600), pass the file path as the argument, and delete the file immediately after. This is a last resort — prefer programs that support env var or stdin input.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This is a good fallback pattern for programs that don't support environment variables. To make the guidance more robust and secure, you could explicitly mention using mktemp for creating the temporary file and trap for ensuring cleanup. This provides more specific instructions for implementing this pattern safely.

  - When the target program only accepts secrets as arguments (no env var support), write the secret to a temporary file (e.g., using `mktemp`, with mode 0600), pass the file path as the argument, and ensure the file is deleted immediately after (e.g., using a `trap` command). This is a last resort — prefer programs that support env var or stdin input.

@marcusquinn marcusquinn added the review-feedback-scanned Merged PR already scanned for quality feedback label Mar 15, 2026
alex-solovyev added a commit that referenced this pull request Mar 15, 2026
…lback

Addresses review feedback from PR #4941 (Gemini Code Assist) by making
the temporary file pattern more specific: recommend mktemp for file
creation and trap for guaranteed cleanup on exit or error.

Closes #4943
alex-solovyev added a commit that referenced this pull request Mar 15, 2026
…lback (#4951)

Addresses review feedback from PR #4941 (Gemini Code Assist) by making
the temporary file pattern more specific: recommend mktemp for file
creation and trap for guaranteed cleanup on exit or error.

Closes #4943
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Auto-created from TODO.md tag review-feedback-scanned Merged PR already scanned for quality feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Secret value exposed in conversation via command argument echo-back

2 participants