presidentbeef/brakeman · error · ArgumentError

Invalid GitHub repository format

Error message

Invalid GitHub repository format

What it means

`--github-repo` tells Brakeman to build clickable source links into GitHub from warning locations. The value must be of the form `owner/repo[/subpath][@ref]` (e.g. `myorg/myapp@main`). `Brakeman.get_github_url` splits the value on `@` then `/`; if it cannot extract a non-empty owner and repo segment, it raises `ArgumentError`.

Source

Thrown at lib/brakeman.rb:350

      when /\.sarif$/i
        :to_sarif
      when /\.sonar$/i
        :to_sonar
      when /\.github$/i
        :to_github
      else
        :to_text
      end
    end
  end
  private_class_method :get_formats_from_output_files

  def self.get_github_url options
    if github_repo = options[:github_repo]
      full_repo, ref = github_repo.split '@', 2
      name, repo, path = full_repo.split '/', 3
      unless name && repo && !(name.empty? || repo.empty?)
        raise ArgumentError, "Invalid GitHub repository format"
      end
      path.chomp '/' if path
      ref ||= 'master'
      ['https://github.com', name, repo, 'blob', ref, path].compact.join '/'
    else
      nil
    end
  end
  private_class_method :get_github_url

  #Output list of checks (for `-k` option)
  def self.list_checks options
    require 'brakeman/scanner'

    add_external_checks options

    if options[:list_optional_checks]
      $stderr.puts "Optional Checks:"

View on GitHub (pinned to 649e678d0a)

Solutions

  1. Use the plain `owner/repo` slug: `--github-repo myorg/myapp`.
  2. Optionally add a subpath and/or ref: `--github-repo myorg/myapp/spec@develop` (ref defaults to `master` when omitted).
  3. If the value comes from CI variables, strip the URL prefix first, e.g. use `$GITHUB_REPOSITORY` (already `owner/repo`) instead of the full repository URL.

Example fix

# before
brakeman --github-repo https://github.com/myorg/myapp   # => ArgumentError: Invalid GitHub repository format

# after
brakeman --github-repo myorg/myapp
# or with branch ref
brakeman --github-repo myorg/myapp@main
Defensive patterns

Strategy: validation

Validate before calling

# Ruby, validate before passing to Brakeman
def valid_github_repo?(value)
  value.match?(%r{\A[\w.-]+/[\w.-]+(/[^@]*)?(@\S+)?\z})
end

repo = ENV['GITHUB_REPOSITORY'] # already 'owner/repo'
raise ArgumentError, 'Invalid GitHub repository format' unless valid_github_repo?(repo)

Try / catch

begin
  Brakeman.run :app_path => app, :github_repo => repo
rescue ArgumentError => e
  abort "#{e.message} — pass owner/repo (optionally /path@ref), not a full URL." if e.message == 'Invalid GitHub repository format'
  raise
end

Prevention

When it happens

Trigger: Passing a bare repo name (`--github-repo myapp`), an empty segment (`--github-repo myorg/` or `--github-repo /myapp`), or — most commonly — a full URL like `--github-repo https://github.com/myorg/myapp`, which splits into `['https:', '', 'github.com/myorg/myapp']` and fails the non-empty repo check.

Common situations: CI configuration where the repository URL from an environment variable or the pipeline's repo setting (`$CI_REPOSITORY_URL`, `$GITHUB_REPOSITORY_URL`) is pasted directly into `--github-repo`; copy-pasting the browser URL instead of the `owner/repo` slug; forgetting the repo half when only intending the owner.

Related errors


AI-assisted analysis of presidentbeef/brakeman@649e678d0a (2026-08-21). Data as JSON: /api/errors/7e990a0c0c68de57. Report an issue: GitHub.