Skip to content

fix(guardrails): push block regex bypassed by flags between push and remote #104

Closed

Description

@terisuke

Problem

git push --force origin main bypasses the protected branch push block in guardrail.ts because the regex \bgit\s+push\s+\S+\s+(?:HEAD:)?(\S+)/i matches --force as the remote name.

Root cause

The regex expects exactly: git push <remote> <branch> but doesn't account for flags like --force, -f, --no-verify between push and the remote.

Fix

Add optional flag group before remote: (?:(?:-\w+|--[\w-]+)\s+)*

// Before
cmd.match(/\bgit\s+push\s+\S+\s+(?:HEAD:)?(\S+)/i)
// After
cmd.match(/\bgit\s+push\s+(?:(?:-\w+|--[\w-]+)\s+)*\S+\s+(?:HEAD:)?(\S+)/i)

Ref

PR #102 code-reviewer HIGH-2. guardrail.ts:~514

Activity

  1. added a commit that references this issue on Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions