An open API service indexing awesome lists of open source software.

https://github.com/h7ml/security-auto-scan

๐Ÿ” ่‡ชๅŠจๆ‰ซๆๅ’Œๆธ…็† GitHub Actions ไธญ็š„ๆถๆ„ workflow ๆ–‡ไปถ | ๆ—ฅๅฟ—ๅŠ ๅฏ† | API ๆ™บ่ƒฝ้‡่ฏ• | ๅคšๆ ผๅผๆŠฅๅ‘Š | Webhook ้€š็Ÿฅ
https://github.com/h7ml/security-auto-scan

automation cicd devops github-actions github-api malware-detection python security security-tools supply-chain vulnerability-scanner workflow

Last synced: 4 months ago
JSON representation

๐Ÿ” ่‡ชๅŠจๆ‰ซๆๅ’Œๆธ…็† GitHub Actions ไธญ็š„ๆถๆ„ workflow ๆ–‡ไปถ | ๆ—ฅๅฟ—ๅŠ ๅฏ† | API ๆ™บ่ƒฝ้‡่ฏ• | ๅคšๆ ผๅผๆŠฅๅ‘Š | Webhook ้€š็Ÿฅ

Awesome Lists containing this project

README

          

# Security Auto Scan Action

![Security](https://img.shields.io/badge/security-auto--scan-red?style=for-the-badge)
![Python](https://img.shields.io/badge/python-3.11-blue?style=for-the-badge)
[![License](https://img.shields.io/github/license/h7ml/security-auto-scan?style=for-the-badge)](LICENSE)
[![GitHub release](https://img.shields.io/github/v/release/h7ml/security-auto-scan?style=for-the-badge)](https://github.com/h7ml/security-auto-scan/releases)
[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Security%20Auto%20Scan-blue?style=for-the-badge&logo=github)](https://github.com/marketplace/actions/security-auto-scan)

[![GitHub stars](https://img.shields.io/github/stars/h7ml/security-auto-scan?style=social)](https://github.com/h7ml/security-auto-scan/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/h7ml/security-auto-scan?style=social)](https://github.com/h7ml/security-auto-scan/network/members)
[![GitHub watchers](https://img.shields.io/github/watchers/h7ml/security-auto-scan?style=social)](https://github.com/h7ml/security-auto-scan/watchers)
[![GitHub issues](https://img.shields.io/github/issues/h7ml/security-auto-scan)](https://github.com/h7ml/security-auto-scan/issues)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/h7ml/security-auto-scan)](https://github.com/h7ml/security-auto-scan/pulls)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/h7ml/security-auto-scan/test.yml?branch=main&label=tests)](https://github.com/h7ml/security-auto-scan/actions)

**Automatically scan and clean malicious workflow files in GitHub Actions**

[English](./README.md) | [็ฎ€ไฝ“ไธญๆ–‡](./README_zh-CN.md)

## ๐Ÿ“– Introduction

Security Auto Scan is a GitHub Action that automatically detects and removes malicious workflow files. Features:

- ๐Ÿ” **Auto Scan** all your repositories (personal + organizations)
- ๐Ÿงน **Auto Clean** detected malicious files
- ๐Ÿ” **Log Masking** automatically hide sensitive information using GitHub Actions `::add-mask::`
- ๐Ÿ“Š **Generate Reports** detailed scan and cleanup reports
- ๐Ÿšจ **Create Issues** automatically create alerts when threats are found
- ๐Ÿ“ข **Webhook Notifications** support Slack/Discord/Teams/DingTalk/Feishu, etc.
- ๐Ÿ’พ **Cache Optimization** avoid duplicate cloning, improve performance by 50-80%
- ๐Ÿ›ก๏ธ **Security First** won't delete important files, won't disable itself

## ๐ŸŽฏ Use Cases

### Supply Chain Attack Response

If your GitHub account is compromised, attackers might:

1. Inject malicious workflow files
2. Steal your GitHub Secrets
3. Exfiltrate data through domains like `*.oast.fun`

**This Action helps you clean all infected repositories with one click!**

### Regular Security Scanning

Even without an attack, regular scanning is recommended:

- Auto scan daily (cron: '0 3 * * *')
- Immediate alert on suspicious files
- Protect your code and Secrets

## ๐Ÿš€ Quick Start

### 1. Create Workflow File

Create `.github/workflows/security-scan.yml` in your repository:

```yaml
name: Security Scan

on:
# Auto scan daily at 3 AM
schedule:
- cron: '0 3 * * *'

# Manual trigger
workflow_dispatch:
inputs:
keyword:
description: 'Search keyword'
required: false
default: '.oast.fun'
dry_run:
description: 'Scan only (true/false)'
required: false
default: 'false'

jobs:
security-scan:
runs-on: ubuntu-latest

permissions:
contents: write
actions: write
issues: write

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Security Auto Scan
uses: h7ml/security-auto-scan@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
keyword: ${{ github.event.inputs.keyword || '.oast.fun' }}
dry-run: ${{ github.event.inputs.dry_run || 'false' }}
create-issue: 'true'
mask-sensitive-data: 'true'
```

### 2. Configure Token

**Option A: Use default GITHUB_TOKEN (Recommended)**

The default `GITHUB_TOKEN` can only access the current repository. To scan all repositories, use Option B.

**Option B: Use Personal Access Token**

1. Visit https://github.com/settings/tokens/new
2. Create Token with permissions:
- โœ… `repo` - Full repository access
- โœ… `workflow` - Workflow permission
3. Add Token to repository Secrets:
- Settings โ†’ Secrets โ†’ Actions โ†’ New repository secret
- Name: `SECURITY_SCAN_TOKEN`
- Value: Paste your Token

4. Update workflow:
```yaml
with:
github-token: ${{ secrets.SECURITY_SCAN_TOKEN }}
```

### 3. Run Scan

**Auto Run**: Executes daily at 3 AM

**Manual Run**:
1. Go to Actions tab
2. Select "Security Scan"
3. Click "Run workflow"
4. Configure parameters and run

## ๐Ÿ“‹ Input Parameters

| Parameter | Required | Default | Description |
|-----------|----------|---------|-------------|
| `github-token` | โœ… | - | GitHub Token (requires `repo` and `workflow` permissions) |
| `keyword` | โŒ | `.oast.fun` | Search keyword (malicious signature) |
| `dry-run` | โŒ | `false` | Scan-only mode (no cleanup) |
| `create-issue` | โŒ | `true` | Create Issue when threats found |
| `disable-workflows` | โŒ | `false` | Disable workflows in infected repositories |
| `mask-sensitive-data` | โŒ | `true` | Log masking (auto-hide sensitive info) |
| `notification-webhook` | โŒ | `` | Webhook URL (Slack/Teams/Discord support) |
| `notification-template` | โŒ | `detailed` | Notification template (`compact` or `detailed`) |

## ๐Ÿ“ค Outputs

| Output | Description |
|--------|-------------|
| `infected-repos` | Number of infected repositories |
| `success-count` | Number of successful cleanups |
| `failed-count` | Number of failed cleanups |
| `report-path` | Scan report path |

### Output Usage Example

```yaml
- name: Security Auto Scan
id: scan
uses: h7ml/security-auto-scan@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check results
run: |
echo "Found ${{ steps.scan.outputs.infected-repos }} infected repositories"
echo "Cleaned successfully ${{ steps.scan.outputs.success-count }}"
echo "Failed to clean ${{ steps.scan.outputs.failed-count }}"
```

## ๐Ÿ“Š Features

### โœ… Smart Scanning

- Search all your repositories (personal + organizations)
- Use GitHub Code Search API (fast, precise)
- **Pagination support**: automatically fetch all matching results (up to 1000)
- Exclude specific files (e.g., `security-auto-scan.yml`)
- Won't disable current repository workflows

### ๐Ÿงน Auto Cleanup

- Clone infected repositories
- Delete malicious workflow files
- Commit and push cleanup
- Record deletion history

### ๐Ÿ” Security Features

- **Log Masking**: use GitHub Actions `::add-mask::` to auto-hide sensitive info (Token, URL, etc.)
- **Configuration Toggle**: support enable/disable masking
- **Minimum Privilege**: only requires `repo` and `workflow` permissions
- **Prevent Mis-deletion**: exclusion list, won't delete important files
- **Skip Current Repo**: won't disable self

### ๐Ÿ“ข Notification Integration

- **Webhook Support**: Slack/Discord/Teams/DingTalk/Feishu, etc.
- **Notification Templates**: compact and detailed templates
- **Auto Trigger**: auto send when threats found
- **Flexible Config**: customizable notification content

### ๐Ÿ”ง Error Handling

- Detailed push failure analysis
- Auto retry (pull before push on conflict)
- Record failed repositories and reasons
- Provide manual cleanup guide

### ๐Ÿ“ˆ Performance Optimization

- Cache cloned repositories
- Avoid duplicate cloning
- Speed up by 50-80% on subsequent runs
- Auto clean cache older than 7 days

### ๐Ÿ“ Reports and Notifications

- Generate detailed scan reports
- Auto create alert Issues
- Upload Artifacts (30-day retention)
- Failed repository list and manual cleanup steps

## ๐Ÿ›ก๏ธ Security

### Token Security

- **Minimum Privilege**: only requires `repo` and `workflow` permissions
- **Temporary Token**: recommend 90-day expiration
- **Revoke After Use**: immediately revoke Token after scan
- **Log Masking**: auto-hide Token to prevent leakage

### Data Privacy

- **Local Processing**: all data processed in Actions Runner
- **No Upload**: won't upload your code to third-party services
- **Reports Only**: only commit scan reports, not logs

### Prevent Mis-deletion

- **Exclusion List**: won't delete `security-auto-scan.yml`
- **Skip Current Repo**: won't disable self
- **Scan-only Mode**: support scan before deciding to clean

## ๐Ÿ“– Advanced Usage

See [EXAMPLES.md](./EXAMPLES.md) for more examples:

- Basic example
- Complete configuration
- Scan-only mode
- Multi-keyword scanning
- Webhook notification integration
- Log masking configuration
- Matrix strategy scanning

## ๐Ÿ—๏ธ Technical Architecture

- **Language**: Python 3.11
- **Core Library**: requests
- **Runtime**: GitHub Actions (ubuntu-latest)
- **Cache Mechanism**: `.alcache` directory for cloned repos
- **Log Masking**: GitHub Actions `::add-mask::` workflow command

## ๐Ÿค Contributing

Contributions welcome! See [CONTRIBUTING.md](./CONTRIBUTING.md)

## ๐Ÿ“„ License

[MIT License](./LICENSE)

## ๐Ÿ™ Acknowledgements

- Inspired by real GitHub Actions supply chain attack incidents
- Thanks to all contributors and user feedback
- Referenced industry security best practices

## ๐Ÿ“ž Support

- ๐Ÿ› [Report Issues](https://github.com/h7ml/security-auto-scan/issues)
- ๐Ÿ’ฌ [Discussions](https://github.com/h7ml/security-auto-scan/discussions)
- ๐Ÿ“ง Email: h7ml@qq.com

## ๐Ÿ” Related Resources

- [GitHub Actions Security Best Practices](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions)
- [GitHub Code Scanning](https://docs.github.com/en/code-security/code-scanning)
- [GitHub Secret Scanning](https://docs.github.com/en/code-security/secret-scanning)

---

**If this Action helps you, please give it a โญ๏ธ Star!**

Made with โค๏ธ by [h7ml](https://github.com/h7ml)