Skip to content

safe-outputs.jobs custom jobs are not gated on threat detection (built-in safe_outputs is) #69404

Closed

Description

@ekbritecore

Analysis

Custom safe-output jobs (safe-outputs.jobs.<name>) run even when threat detection fails; the built-in safe_outputs job does not.

buildSafeJobs in pkg/workflow/safe_jobs.go (v0.92.3) adds needs: [agent, detection] with the comment "so that the condition can gate on needs.detection.result == 'success'", but only adds that gate when IsConditionalDetection(...) is true. With ordinary always-on detection the compiled condition is:

(!cancelled()) && needs.agent.result != 'skipped' && contains(needs.agent.outputs.output_types, '<job>')

!cancelled() lets the job run after a failed detection job, so any custom write (Slack, an external API) bypasses detection. safe_outputs uses ... && needs.detection.result == 'success'.

Reproduce: compile any workflow with a safe-outputs.jobs entry and default detection; compare jobs.<name>.if with jobs.safe_outputs.if in the lock.

Implementation Plan

  1. pkg/workflow/safe_jobs.go (buildSafeJobs): when threatDetectionEnabled and not IsConditionalDetection, AND the base condition with buildDetectionSuccessCondition() (same gate as safe_outputs).
  2. Pass GH_AW_DETECTION_CONCLUSION: ${{ needs.detection.outputs.detection_conclusion }} to custom job steps, as the built-in job receives it.
  3. Tests next to the existing safe-jobs tests: the condition contains needs.detection.result == 'success' when detection is enabled, and is unchanged when detection is disabled or expression-controlled.
  4. Run make agent-finish before completing.

Acceptance Criteria

With threat detection enabled, a failed detection job skips every safe-outputs.jobs.* job, as it skips safe_outputs; the new tests pass.

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions