Scanner#internal_host? treats unresolvable or offline hosts as internal because [].all? is true

Open Beginner friendly
#480 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
ruby
Domain
security

Research direction

The bug is in Scanner#internal_host? in lib/bundler/audit/scanner.rb, which calls Resolv.getaddresses(host).all?; an empty result makes [].all? return true and marks the source as internal. Start by reading that method and internal_source?, then reproduce with a host that does not resolve (for example gems.example.invalid). Done when an unresolvable http:// or git:// source is reported as an insecure source and the command exits with status 1.

Written by the indexing model from the issue text.

Description

Description

bundle-audit check skips InsecureSource warnings whenever Resolv.getaddresses(host) returns an empty array (for example when running offline without DNS access, despite the README noting that bundler-audit does not require a network connection, or when a source hostname in Gemfile.lock no longer resolves).

In lib/bundler/audit/scanner.rb, Scanner#internal_host? runs Resolv.getaddresses(host).all? { |ip| internal_ip?(ip) }. When Resolv.getaddresses(host) returns [], [].all? evaluates to true, so internal_source? treats the http:// or git:// source as a private internal IP.

Steps To Reproduce

Steps to reproduce the bug:

gem install rake -v 13.2.1
bundler-audit update

mkdir repro && cd repro
printf 'source "http://rubygems.org"\ngem "rake", "13.2.1"\n' > Gemfile
bundle lock --local

# Online: reports Insecure Source URI found: http://rubygems.org/ (exit 1)
bundle-audit check --no-update

# Offline (Linux network namespace with loopback up, like docker run --network none):
unshare -rn sh -c 'ip link set lo up && bundle-audit check --no-update'

The same happens while online on any OS if the http:// or git:// host does not resolve in DNS (source "http://gems.example.invalid").

Expected Behavior

bundle-audit check --no-update reports the http:// source and exits with status 1:

Insecure Source URI found: http://rubygems.org/
Vulnerabilities found!

Actual Behavior

No vulnerabilities found

Exit status is 0. Reproduces on bundler-audit 0.9.3 and current master (3cd866bedf).

Environment

$ bundler-audit --version
bundler-audit 0.9.3
$ bundle --version
Bundler version 2.6.9
$ ruby --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux-gnu]
$ git --version
git version 2.39.5

Also tested against master at commit 3cd866bedf609aa2c98a464909602f595265ae49 on Debian x86_64.

Found with a differential-testing tool; the report was drafted with AI assistance and reviewed and edited by me.

Credit: https://ucsbplse.github.io/

Dominant language
Ruby
Stars
2.8k
Forks
243
Avg merge
1d 13h
Merged PRs (30d)
9

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rubysec/bundler-audit

All issues in rubysec/bundler-audit

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.