Kiểm tra GitHub Actions & GitLab CI API

Kiểm tra workflow GitHub Actions, action.yml, .gitlab-ci.yml: JSON Schema, needs, biểu thức ${{ }}, cron, action chưa pin, lỗ hổng script injection.

GETPOSThttps://apibox.io.vn/v1/ci-validate
Tiện ích lập trình▶ Dùng thử online

Gửi file YAML (văn bản, file hoặc body thô); loại file được tự nhận diện (hoặc đặt type là github-workflow, github-action, gitlab-ci). Bước 1 kiểm tra theo JSON Schema chính thức (SchemaStore github-workflow / github-action, ci.json của GitLab, cập nhật hằng tuần), báo lỗi cụ thể nhất cho từng vị trí kèm số dòng YAML. Lỗi cú pháp YAML và khoá trùng cũng được phát hiện.

Bước 2 kiểm tra ngữ nghĩa và bảo mật: needs trỏ job không tồn tại hoặc tạo vòng lặp, cú pháp biểu thức ${{ }} (chuỗi dùng nháy kép, hàm / context lạ) và context có dùng được ở vị trí đó không (ví dụ secrets trong if, matrix trong if của job), tham chiếu steps.<id> / needs.<job>, matrix rỗng, cú pháp và tần suất cron, runner đã ngừng (ubuntu-20.04, windows-2019, macos-13…) và phiên bản action đã chết (upload-artifact v3, cache v2), action chưa pin theo commit SHA (rủi ro chuỗi cung ứng), pull_request_target + checkout code PR (pwn request), script injection từ tiêu đề issue / PR và commit message, permissions quá rộng, lệnh ::set-output cũ, secret in ra log. Với GitLab: stage không khai báo, đích của needs / dependencies / extends, needs vào stage sau, dùng rules cùng only/except, secret ghi thẳng trong variables.

Kết quả kèm danh sách job và phụ thuộc, sơ đồ Mermaid và mọi action được dùng. Quy tắc do chúng tôi tự viết (tham khảo danh sách quy tắc công khai của actionlint). Liên quan: /v1/dockerfile-lint, /v1/k8s-validate, /v1/cron.

Markdown · OpenAPI · Postman · llms.txt

Tham số

TênVị tríKiểuBắt buộcMặc định
yamlbodystringcóNội dung workflow / action.yml / .gitlab-ci.yml (hoặc file / body thô; tối đa 1 MB).
typebody|querystringkhôngautoauto, github-workflow, github-action hoặc gitlab-ci.
schemabody|querybooleankhôngtrueChạy kiểm tra JSON Schema.

Ví dụ

curl -X POST "https://apibox.io.vn/v1/ci-validate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"yaml":"name: CI\non: [push, pull_request]\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - uses: actions/setup-node@v4\n        with:\n          node-version: 22\n      - run: npm ci && npm test\n  deploy:\n    needs: [test, build]\n    if: ${{ github.ref == \"refs/heads/main\" }}\n    runs-on: ubuntu-latest\n    steps:\n      - run: echo \"${{ github.event.head_commit.message }}\"\n"}'

Kết quả trả về

{
  "valid": false,
  "type": "github-workflow",
  "errors": 3,
  "warnings": 0,
  "info": 3,
  "findings": [
    {
      "rule": "permissions-missing",
      "severity": "info",
      "message": "No top-level \"permissions\": the GITHUB_TOKEN gets the repository default (often read-write); set permissions: contents: read and widen per job",
      "path": "",
      "line": 1
    },
    {
      "rule": "action-not-pinned",
      "severity": "info",
      "message": "actions/checkout@v4 uses the mutable ref \"v4\"; pin actions to a full commit SHA (owner/repo@<40-hex> # v4) — a moved tag runs new code with your secrets (e.g. tj-actions/changed-files, March 2025)",
      "path": "jobs.test.steps.0.uses",
      "line": 7
    },
    "…",
    {
      "rule": "needs-unknown",
      "severity": "error",
      "message": "Job \"deploy\" needs \"build\", which does not exist (jobs: test, deploy)",
      "path": "jobs.deploy.needs",
      "line": 13
    },
    {
      "rule": "expression-syntax",
      "severity": "error",
      "message": "Expression \"github.ref == \"refs/heads/main\"\": string literals use single quotes in GitHub expressions ('text'), not double quotes",
      "path": "jobs.deploy.if",
      "line": 14
    },
    {
      "rule": "script-injection",
      "severity": "error",
      "message": "github.event.head_commit.message is attacker-controlled and is pasted into the script: pass it through env (env: TITLE: ${{ github.event.head_commit.message }}) and use \"$TITLE\"",
      "path": "jobs.deploy.steps.0.run",
      "line": 17
    }
  ],
  "jobs": [
    {
      "id": "test",
      "needs": []
    },
    {
      "id": "deploy",
      "needs": [
        "test",
        "build"
      ]
    }
  ],
  "actions": [
    "actions/checkout@v4",
    "actions/setup-node@v4"
  ],
  "mermaid": "graph LR\n  test[\"test\"]\n  test --> deploy\n  build --> deploy",
  "schema": {
    "name": "github-workflow",
    "source": "https://www.schemastore.org/github-workflow.json",
    "licence": "Apache-2.0 (SchemaStore)",
    "built": "2026-11-16"
  },
  "note": "Kubernetes manifests: /v1/k8s-validate; Dockerfiles: /v1/dockerfile-lint."
}

Ứng dụng

  • Kiểm tra thay đổi workflow trong pre-commit hook hoặc bot review
  • Tìm action bên thứ ba chưa pin SHA trên nhiều repo
  • Bắt mẫu pwn request và script injection trước khi merge
  • Kiểm tra stage và needs của .gitlab-ci.yml mà không cần chạy pipeline

Hỏi đáp

Dùng schema nào?

github-workflow và github-action của SchemaStore (Apache-2.0) và ci.json của chính GitLab (MIT), đóng gói sẵn và cập nhật hằng tuần.

Vì sao cảnh báo tag kiểu @v4?

Tag có thể bị dời sang mã độc (như vụ tj-actions/changed-files tháng 3/2025); commit SHA đầy đủ thì không. Action chính chủ actions/* báo mức info, action bên thứ ba báo warning.

Có theo reusable workflow và include không?

Không: chỉ kiểm tra file bạn gửi; với GitLab, job tham chiếu tới file include không bị báo là không tồn tại khi file có include.

API liên quan

Bắt đầu với 1.000 request miễn phí mỗi tháng. Nhận API key miễn phí →