Skip to content

feat(allowlist): protect per-environment .env files - #1279

Merged
lizhengfeng101 merged 2 commits into
alibaba:mainfrom
hyy321:feat/env-secret-patterns
Sep 15, 2026
Merged

lizhengfeng101 merged 2 commits into
alibaba:mainfrom
hyy321:feat/env-secret-patterns

Conversation

@hyy321

@hyy321 hyy321 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Description

This PR extends the built-in secret-path protection added in #1262 to cover common per-environment files such as .env.production, .env.staging, and .env.development.

The existing .env.local and .env.*.local patterns are replaced by the broader .env.* pattern. .env.example, .env.sample, and .env.template remain exempt from that rule so committed template files can still be reviewed normally.

The template exception applies only to the .env.* rule and does not bypass other secret-path protections. For example, .ssh/.env.example is still excluded by the existing .ssh/** rule.

The existing secret_exclude precedence and review/scan selection behavior remain unchanged. The localized review-rules documentation has also been updated to describe the template exceptions.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make test passes locally
  • Manual testing (describe below)

Additional validation:

  • go test -run TestIsSecretPath -count=1 ./internal/config/allowlist
  • go test ./internal/config/allowlist
  • make check
  • make build
  • git diff --cached --check
  • Local OCR self-review with deepseek-v4-pro: 0 findings across 2 selected items

Tests cover per-environment .env.* paths, template exceptions, case-insensitive matching, and ensure template exceptions do not bypass other secret-path rules.

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

AI/LLM Disclosure

AI/LLM tools were used during implementation and review.

Tools: Codex and OpenCodeReview.
OCR self-review model: deepseek-v4-pro.

I reviewed the final implementation, diff, and test results before submission.

Related Issues

Closes #1265

Follow-up to #1262

@github-actions

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s).

envTemplate := isEnvTemplate(lowerPath)
for _, pattern := range secretPatterns {
// Template names are exempt only from the broad .env.* rule.
if envTemplate && pattern == "**/.env.*" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@hyy321 There is an implicit string-based coupling between the Go code and the JSON; this implementation is prone to errors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I’ll remove the dependency on the literal JSON pattern and handle per-environment .env.* paths directly in the matcher. Existing secret patterns will still use the JSON-based matching path, so template exceptions won’t bypass rules such as .ssh/**.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated. The .env family is now handled directly by the matcher, and the .env patterns have been removed from default_secret_patterns.json. The JSON list now only contains unconditional secret-path globs, so there is no longer a literal dependency between the Go logic and the JSON patterns. Template paths still fall through to the remaining rules, so cases such as .ssh/.env.example remain protected.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I’ll remove the dependency on the literal JSON pattern and handle per-environment .env.* paths directly in the matcher. Existing secret patterns will still use the JSON-based matching path, so template exceptions won’t bypass rules such as .ssh/**.

"**/.env",
"**/.env.local",
"**/.env.*.local",
"**/.env.*",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"**/.env.*",
"**/*.env.*",

Use this so that doesn't omit config.env.example, which is also common.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is addressed by the latest change. The .env family is no longer matched through a JSON glob and is handled directly by the matcher instead, so this pattern replacement no longer applies.

@lizhengfeng101

Copy link
Copy Markdown
Contributor

@hyy321 CI / test (pull_request)Failing after 4m

@hyy321

hyy321 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

@hyy321 CI / test (pull_request)Failing after 4m

I traced the failure to TestCloseAll_TimeoutPreservesCollectedErrors in internal/mcp. This PR does not touch the MCP package. I also ran the same CI command locally successfully, and the failing test passes 3 consecutive runs with -race. The surrounding stress tests already account for -race timing differences, so this looks like a timing-sensitive flake. I don't appear to have permission to rerun the failed job; could you rerun it?

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 89b0d2a into alibaba:main Sep 15, 2026
20 of 22 checks passed
@hyy321
hyy321 deleted the feat/env-secret-patterns branch September 16, 2026 07:54
Githab-capibara added a commit to Githab-capibara/open-code-review that referenced this pull request Sep 17, 2026
* feat(allowlist): protect per-environment .env files

* fix(allowlist): decouple env secret matching
kall added a commit to kall/open-code-review that referenced this pull request Sep 28, 2026
…m rules

The v1.12.9 merge passed build, vet and the full test suite, yet the
branch-only coreFilterReason still lacked the secret-path gate upstream
added in alibaba#1262/alibaba#1279. Both parity tables only knew the old cases, so
they stayed green until matching secret cases were added. Record the
procedure: diff upstream's source-of-truth filter and allowlist data
across the tag range, add parity cases for each new branch first and
check that only the copy fails, pick fixture paths that no built-in
list covers, and diff the merge result against the upstream tag to
catch resurrected dead code such as executePlanPhase.

CONCEPTS.md: refine Exclude Reason (secret, provider-directory and
too-large reasons now exist), File Filter (include cannot admit
credential paths or provider directories) and Review parity (tests
assert only the cases they list).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@verdrellw60-max verdrellw60-max left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • [ ]

@verdrellw60-max verdrellw60-max left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

>>

@verdrellw60-max verdrellw60-max left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Trace

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(allowlist): cover per-environment .env.* files in secret-path protection

4 participants