merge: phase 14-04 register wiring
This commit is contained in:
@@ -4,9 +4,14 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
<<<<<<< HEAD
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
=======
|
||||
"io"
|
||||
"net/http"
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
"time"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
@@ -16,19 +21,30 @@ import (
|
||||
)
|
||||
|
||||
// GitHubActionsSource searches GitHub Actions workflow run logs for leaked API
|
||||
<<<<<<< HEAD
|
||||
// keys. It queries the GitHub REST API for workflow runs matching provider
|
||||
// keywords (via the repository search endpoint) and emits findings for each
|
||||
// matching run. Requires a GitHub token (same as GitHubSource).
|
||||
=======
|
||||
// keys. Workflow logs are public for public repositories and frequently contain
|
||||
// accidentally printed secrets, debug output with credentials, or insecure
|
||||
// echo statements that expose environment variables.
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
type GitHubActionsSource struct {
|
||||
Token string
|
||||
BaseURL string
|
||||
Registry *providers.Registry
|
||||
Limiters *recon.LimiterRegistry
|
||||
<<<<<<< HEAD
|
||||
client *Client
|
||||
=======
|
||||
Client *Client
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
}
|
||||
|
||||
var _ recon.ReconSource = (*GitHubActionsSource)(nil)
|
||||
|
||||
<<<<<<< HEAD
|
||||
func (s *GitHubActionsSource) Name() string { return "github_actions" }
|
||||
func (s *GitHubActionsSource) RateLimit() rate.Limit { return rate.Every(2 * time.Second) }
|
||||
func (s *GitHubActionsSource) Burst() int { return 2 }
|
||||
@@ -54,27 +70,68 @@ func (s *GitHubActionsSource) Sweep(ctx context.Context, _ string, out chan<- re
|
||||
if s.Token == "" {
|
||||
return nil
|
||||
}
|
||||
=======
|
||||
func (s *GitHubActionsSource) Name() string { return "ghactions" }
|
||||
func (s *GitHubActionsSource) RateLimit() rate.Limit { return rate.Every(2 * time.Second) }
|
||||
func (s *GitHubActionsSource) Burst() int { return 3 }
|
||||
func (s *GitHubActionsSource) RespectsRobots() bool { return false }
|
||||
|
||||
// Enabled requires a GitHub token (reuses GitHubToken from SourcesConfig).
|
||||
func (s *GitHubActionsSource) Enabled(_ recon.Config) bool { return s.Token != "" }
|
||||
|
||||
// ghActionsRunsResponse represents the GitHub Actions workflow runs list.
|
||||
type ghActionsRunsResponse struct {
|
||||
WorkflowRuns []ghActionsRun `json:"workflow_runs"`
|
||||
}
|
||||
|
||||
type ghActionsRun struct {
|
||||
ID int64 `json:"id"`
|
||||
LogsURL string `json:"logs_url"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
Status string `json:"status"`
|
||||
Conclusion string `json:"conclusion"`
|
||||
}
|
||||
|
||||
func (s *GitHubActionsSource) Sweep(ctx context.Context, _ string, out chan<- recon.Finding) error {
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
base := s.BaseURL
|
||||
if base == "" {
|
||||
base = "https://api.github.com"
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
if s.client == nil {
|
||||
s.client = NewClient()
|
||||
}
|
||||
|
||||
queries := BuildQueries(s.Registry, "github_actions")
|
||||
kwIndex := ghActionsKeywordIndex(s.Registry)
|
||||
=======
|
||||
client := s.Client
|
||||
if client == nil {
|
||||
client = NewClient()
|
||||
}
|
||||
|
||||
queries := BuildQueries(s.Registry, "ghactions")
|
||||
if len(queries) == 0 {
|
||||
return nil
|
||||
}
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
|
||||
for _, q := range queries {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
if s.Limiters != nil {
|
||||
if err := s.Limiters.Wait(ctx, s.Name(), s.RateLimit(), s.Burst(), false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// Search for workflow YAML files referencing the keyword.
|
||||
endpoint := fmt.Sprintf("%s/search/code?q=%s+path:.github/workflows+extension:yml&per_page=20",
|
||||
base, url.QueryEscape(q))
|
||||
@@ -113,11 +170,74 @@ func (s *GitHubActionsSource) Sweep(ctx context.Context, _ string, out chan<- re
|
||||
case out <- f:
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
=======
|
||||
// Search for workflow runs via the Actions API.
|
||||
searchURL := fmt.Sprintf("%s/search/code?q=%s+path:.github/workflows", base, q)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, searchURL, nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+s.Token)
|
||||
req.Header.Set("Accept", "application/vnd.github.v3+json")
|
||||
|
||||
resp, err := client.Do(ctx, req)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
var runs ghActionsRunsResponse
|
||||
if err := json.NewDecoder(resp.Body).Decode(&runs); err != nil {
|
||||
_ = resp.Body.Close()
|
||||
continue
|
||||
}
|
||||
_ = resp.Body.Close()
|
||||
|
||||
for _, run := range runs.WorkflowRuns {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if s.Limiters != nil {
|
||||
if err := s.Limiters.Wait(ctx, s.Name(), s.RateLimit(), s.Burst(), false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch log content.
|
||||
logURL := fmt.Sprintf("%s/actions/runs/%d/logs", base, run.ID)
|
||||
logReq, err := http.NewRequestWithContext(ctx, http.MethodGet, logURL, nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
logReq.Header.Set("Authorization", "Bearer "+s.Token)
|
||||
logReq.Header.Set("Accept", "application/vnd.github.v3+json")
|
||||
|
||||
logResp, err := client.Do(ctx, logReq)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(io.LimitReader(logResp.Body, 256*1024))
|
||||
_ = logResp.Body.Close()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if ciLogKeyPattern.Match(body) {
|
||||
out <- recon.Finding{
|
||||
ProviderName: q,
|
||||
Source: logURL,
|
||||
SourceType: "recon:ghactions",
|
||||
Confidence: "medium",
|
||||
DetectedAt: time.Now(),
|
||||
}
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
func ghActionsKeywordIndex(reg *providers.Registry) map[string]string {
|
||||
m := make(map[string]string)
|
||||
@@ -136,3 +256,5 @@ func ghActionsKeywordIndex(reg *providers.Registry) map[string]string {
|
||||
}
|
||||
return m
|
||||
}
|
||||
=======
|
||||
>>>>>>> worktree-agent-adad8c10
|
||||
|
||||
Reference in New Issue
Block a user