π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[infra] Tighten workflow chec
Manav Rathi8ee56c327451
diff --git a/.github/workflows/security-check-workflows.yml b/.github/workflows/security-check-workflows.ymlindex 0538f475de..4f163e337a 100644--- a/.github/workflows/security-check-workflows.yml+++ b/.github/workflows/security-check-workflows.yml@@ -5,8 +5,11 @@ on:paths:- '.github/workflows/**'+permissions:+ contents: read+jobs:- check-pull-request-target:+ check-privileged-workflow-patterns:runs-on: ubuntu-latestenvironment:name: workflow-security-review@@ -17,46 +20,107 @@ jobs:with:fetch-depth: 0- - name: Check for pull_request_target in modified workflows+ - name: Check for new privileged workflow triggers+ shell: bashrun: |- # Get list of modified workflow files- MODIFIED_WORKFLOWS=$(git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^\.github/workflows/.*\.yml$' || true)+ extract_sensitive_triggers() {+ local revision=$1+ local file=$2++ if ! git cat-file -e "${revision}:${file}" 2>/dev/null; then+ return 0+ fi++ git show "${revision}:${file}" | ruby -e '+ require "date"+ require "yaml"++ sensitive = %w[+ pull_request_target+ issue_comment+ pull_request_review_comment+ discussion_comment+ workflow_run+ ]++ workflow = YAML.safe_load(+ STDIN.read,+ aliases: true,+ permitted_classes: [Date, Time, DateTime]+ ) || {}+ events = case workflow["on"] || workflow[true]+ when String+ [workflow["on"] || workflow[true]]+ when Array+ (workflow["on"] || workflow[true]).grep(String)+ when Hash+ (workflow["on"] || workflow[true]).keys.map(&:to_s)+ else+ []+ end++ puts events.select { |event| sensitive.include?(event) }.uniq.sort+ '+ }- if [ -z "$MODIFIED_WORKFLOWS" ]; then+ mapfile -t modified_workflows < <(+ git diff --name-only --diff-filter=AMR "origin/${{ github.base_ref }}...HEAD" |+ grep -E '^\.github/workflows/.*\.ya?ml$' || true+ )++ if [ "${#modified_workflows[@]}" -eq 0 ]; thenecho "No workflow files modified"exit 0fi- echo "Checking modified workflows: $MODIFIED_WORKFLOWS"+ printf 'Checking modified workflows:\n'+ printf ' - %s\n' "${modified_workflows[@]}"- # Check if any modified workflow introduces pull_request_target- VIOLATIONS=""- for file in $MODIFIED_WORKFLOWS; do- if git show HEAD:$file | grep -q "pull_request_target:"; then- # Check if it existed in base branch- if git show origin/${{ github.base_ref }}:$file 2>/dev/null | grep -q "pull_request_target:"; then- echo "β $file: pull_request_target already existed (allowed)"- else- echo "β $file: NEW pull_request_target trigger detected!"- VIOLATIONS="$VIOLATIONS\n- $file"- fi+ sensitive_triggers=(+ "pull_request_target"+ "issue_comment"+ "pull_request_review_comment"+ "discussion_comment"+ "workflow_run"+ )+ violations=()++ for file in "${modified_workflows[@]}"; do+ if ! current_triggers=$(extract_sensitive_triggers HEAD "$file"); then+ echo "β ERROR: Failed to parse workflow triggers in HEAD:$file"+ exit 1fi++ if ! base_triggers=$(extract_sensitive_triggers "origin/${{ github.base_ref }}" "$file"); then+ echo "β ERROR: Failed to parse workflow triggers in origin/${{ github.base_ref }}:$file"+ exit 1+ fi++ for trigger in "${sensitive_triggers[@]}"; do+ if grep -Fxq "$trigger" <<< "$current_triggers"; then+ if grep -Fxq "$trigger" <<< "$base_triggers"; then+ echo "β $file: ${trigger} already existed (allowed)"+ else+ echo "β $file: NEW ${trigger} trigger detected!"+ violations+=("$file:${trigger}")+ fi+ fi+ donedone- if [ -n "$VIOLATIONS" ]; then+ if [ "${#violations[@]}" -gt 0 ]; thenecho ""- echo "β ERROR: New pull_request_target triggers detected in:$VIOLATIONS"+ echo "β ERROR: New privileged workflow triggers detected:"+ printf ' - %s\n' "${violations[@]}"echo ""- echo "pull_request_target is a security-sensitive trigger that:"- echo "- Runs in the context of the base repository"- echo "- Has access to repository secrets"- echo "- Can be exploited by malicious PRs"+ echo "These triggers can execute with repository trust or be chained"+ echo "from untrusted pull requests into privileged automation."echo ""- echo "If you need to add pull_request_target, please:"+ echo "If you need to add one of these triggers, please:"echo "1. Discuss with maintainers first"- echo "2. Ensure proper security measures are in place"+ echo "2. Ensure the workflow never executes untrusted PR code with write tokens or secrets"echo "3. Get explicit approval before merging"exit 1fi- echo "β No new pull_request_target triggers detected"+ echo "β No new privileged workflow triggers detected"