fix: imported safe-output fragments no longer override explicit threat-detection: false#18231
fix: imported safe-output fragments no longer override explicit threat-detection: false#18231
threat-detection: false#18231Conversation
…t-detection: false When a workflow sets threat-detection: false (or enabled: false), add a ThreatDetectionExplicitlyDisabled flag to SafeOutputsConfig. The flag is set in extractSafeOutputsConfig when the threat-detection key is present but resolves to nil. mergeSafeOutputConfig now guards the ThreatDetection merge with !result.ThreatDetectionExplicitlyDisabled so imported fragments cannot re-enable threat detection that was explicitly disabled. Adds three tests: - TestMergeSafeOutputsThreatDetectionExplicitDisableNotOverridden (unit) - TestMergeSafeOutputsThreatDetectionImportedWhenMainHasNone (regression) - TestSafeOutputsImportDoesNotReenableThreatDetection (integration) Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
threat-detection: false
|
@copilot Review the code and make it as clean and concise as possible. Simplify the implementation to improve clarity and maintainability. |
…instead of sentinel Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Simplified in eb45e44. Replaced the if result.ThreatDetection == nil {
if _, hasTD := config["threat-detection"]; hasTD && importedConfig.ThreatDetection != nil {
result.ThreatDetection = importedConfig.ThreatDetection
}
}This means ThreatDetection is only propagated from an import that explicitly carries a |
This comment has been minimized.
This comment has been minimized.
|
Commit pushed:
|
There was a problem hiding this comment.
Pull request overview
Fixes a merge-time regression where imported safe-outputs fragments could unintentionally re-enable threat detection (via defaulting) even when the main workflow explicitly disabled it.
Changes:
- Gate
ThreatDetectionmerge from imports on the imported fragment explicitly containing athreat-detectionkey. - Add unit/integration coverage to ensure explicit
threat-detection: falsein the main workflow is preserved across imports.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/workflow/imports.go | Prevents imported fragments without an explicit threat-detection key from setting ThreatDetection during merge. |
| pkg/workflow/safe_outputs_import_test.go | Adds tests covering explicit disable preservation and explicit import enable behavior. |
| tmp-smoke-test-22377081592.txt | Adds a temporary smoke-test artifact file (likely unintended). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Simulate main workflow that explicitly disabled threat-detection: | ||
| // threat-detection: false → parseThreatDetectionConfig returns nil. | ||
| topConfig := &SafeOutputsConfig{ | ||
| ThreatDetection: nil, | ||
| AddComments: &AddCommentsConfig{}, | ||
| } | ||
|
|
||
| // Import fragment with safe-outputs but no threat-detection key. | ||
| importedJSON := []string{ | ||
| `{"add-comment":{"max":1}}`, | ||
| } |
There was a problem hiding this comment.
This test doesn’t exercise the regression path because topConfig pre-defines AddComments, so MergeSafeOutputs will delete the imported add-comment entry as an override conflict before mergeSafeOutputConfig runs. That means the test would pass even without the threat-detection merge guard. Consider using a topConfig that represents a workflow with safe-outputs present but without add-comment (e.g., only meta/messages fields) and assert that AddComments is merged while ThreatDetection stays nil.
| @@ -0,0 +1 @@ | |||
| Test file for PR push - smoke test run 22377081592 | |||
There was a problem hiding this comment.
This looks like a temporary CI/smoke-test artifact that shouldn’t be committed to the repository. Please remove this file from the PR (and add it to .gitignore if it’s generated by local/CI workflows).
| Test file for PR push - smoke test run 22377081592 |
…cedence - Add `validate` command section to setup/cli.md (Building section, after compile). The command was added in #18191 but was missing from the main CLI reference page; only the compilation-process.md reference table had been updated. - Add NOTE callout to reference/threat-detection.md clarifying that an explicit `threat-detection: false` in a workflow takes precedence over imported fragments, documenting the behaviour fixed in #18231. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When a workflow sets
threat-detection: false(orenabled: false), imported fragments that lack athreat-detectionkey would silently re-enable it via auto-defaulting inparseThreatDetectionConfig, triggering a spurious validation error whensandbox.agent: falsewas also set.Root cause:
result.ThreatDetection == nilwas ambiguous — it could mean either "not configured" (no safe-outputs in main) or "explicitly disabled", somergeSafeOutputConfigcouldn't distinguish them.Changes
imports.go—ThreatDetectionis only merged from an imported fragment if the fragment's raw config map explicitly contains athreat-detectionkey. Auto-enabled defaults (fragments that have safe-outputs but no explicitthreat-detectionkey) are ignored during merge. This makesthreat-detectiona true workflow-level concern.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.
✨ PR Review Safe Output Test - Run 22377081592