Security and hardening · Intermediate · 22 min
Scan any project for known vulnerabilities with OSV-Scanner
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · OSV-Scanner 2.7.1 · Go 1.27.4
You will install OSV-Scanner 2.7.1 with a checksum check, scan a repository that mixes npm, Python, Go and Maven code in one pass, see which Go findings your code actually calls, record a dated exception, fix the npm lockfile, check licences against an allow-list and run the scan offline.
On this page
A dependency scanner compares the exact package versions your project uses against a database of published advisories. Most ecosystems have their own: npm audit for Node.js, pip-audit for Python, govulncheck for Go. They are good at their own language and blind to the rest. A repository with a React front end, a Python API, a Go worker and a Java billing module needs four tools, four report formats and four places to record exceptions.
OSV-Scanner is Google's open-source answer to that. It reads lockfiles and manifests from more than a dozen ecosystems and checks them all against OSV.dev, an open database that collects advisories from the GitHub Advisory Database, the Python Packaging Advisory Database, the Go vulnerability database, RustSec and others, in one shared format. One command, one report, one configuration file format.
How it compares with the single-language tools:
- npm audit asks the npm registry, which uses GitHub's advisories. OSV.dev includes those, so the npm findings usually match. npm audit can also fix by running npm; OSV-Scanner's fix command edits the lockfile itself.
- pip-audit asks PyPI's vulnerability service by default and can switch to OSV with
-s osv. It audits an installed environment, which OSV-Scanner does not. - OSV-Scanner covers every language at once and, for Go, can tell you whether your code calls the vulnerable function. Keep the native tool where it gives you something extra; use OSV-Scanner as the one gate across the whole repository.
You build a small demo repository in ~/osv-demo with one old dependency per ecosystem, scan it, and work through each feature on real findings. Advisory data changes every day, so the counts you see will differ from the examples; the advisory IDs named here are old and stable.
Step 1 · Install OSV-Scanner 2.7.1 and check the download
OSV-Scanner is a single Go binary. The release page on GitHub has one for each platform plus a file of SHA-256 checksums. Install curl for the download and jq for reading JSON reports later:
sudo apt update
sudo apt install -y curl ca-certificates jqDownload the binary for your processor (amd64 on most servers and laptops, arm64 on ARM cloud servers and a Raspberry Pi) and the checksum file, then check one against the other:
cd ~
ARCH=$(dpkg --print-architecture)
curl -fsSLO "https://github.com/google/osv-scanner/releases/download/v2.7.1/osv-scanner_linux_${ARCH}"
curl -fsSLO "https://github.com/google/osv-scanner/releases/download/v2.7.1/osv-scanner_SHA256SUMS"
grep " osv-scanner_linux_${ARCH}\$" osv-scanner_SHA256SUMS | sha256sum -csha256sum -c prints osv-scanner_linux_amd64: OK (or arm64). Anything else means the file is damaged or not the one Google published; delete it and download again. The binary is about 55 MB, so on prepaid mobile data start the download on Wi-Fi.
Install it to /usr/local/bin and remove the downloads:
sudo install -m 755 "osv-scanner_linux_${ARCH}" /usr/local/bin/osv-scanner
rm "osv-scanner_linux_${ARCH}" osv-scanner_SHA256SUMSA binary installed by hand gets no updates from apt. To upgrade, repeat these commands with the new version number from the releases page. On macOS, brew install osv-scanner works too.
Check it worked
osv-scanner --versionThe first line is osv-scanner version: 2.7.1, followed by the version of the osv-scalibr library it is built on, the commit and the build date.
Step 2 · Build a repository with four ecosystems
Create a demo repository with four parts, each pinned to a release with published advisories:
web/: an npm project locked to lodash 4.17.20.api/: a Python service that pins requests 2.25.0.worker/: a Go program using golang.org/x/text 0.3.5.billing/: a Maven module on log4j-core 2.14.1, the version hit by Log4Shell.
In a real project npm writes package-lock.json for you. Here you write a minimal one by hand so you do not need Node.js installed:
mkdir -p ~/osv-demo/web ~/osv-demo/api ~/osv-demo/worker ~/osv-demo/billing
cd ~/osv-demo/web
cat > package.json <<'EOF'
{
"name": "osv-demo-web",
"version": "1.0.0",
"private": true,
"dependencies": {
"lodash": "^4.17.20"
}
}
EOF
cat > package-lock.json <<'EOF'
{
"name": "osv-demo-web",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "osv-demo-web",
"version": "1.0.0",
"dependencies": {
"lodash": "^4.17.20"
}
},
"node_modules/lodash": {
"version": "4.17.20",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==",
"license": "MIT"
}
}
}
EOFThe Python part is one pinned line, the way pip freeze writes it. The Maven part is a minimal pom.xml:
cd ~/osv-demo
printf 'requests==2.25.0\n' > api/requirements.txt
cat > billing/pom.xml <<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.osvdemo</groupId>
<artifactId>billing</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>
</dependencies>
</project>
EOFThe Go worker reads a language tag such as yo-NG (Yoruba, Nigeria) and prints the language part. It uses language.Parse from golang.org/x/text and nothing else from that package, which matters in the next step but one:
cd ~/osv-demo/worker
cat > go.mod <<'EOF'
module example.com/osv-demo/worker
go 1.27.4
require golang.org/x/text v0.3.5
EOF
cat > main.go <<'EOF'
package main
import (
"fmt"
"os"
"golang.org/x/text/language"
)
func main() {
input := "en-GB"
if len(os.Args) > 1 {
input = os.Args[1]
}
tag, err := language.Parse(input)
if err != nil {
fmt.Println("not a language tag:", err)
return
}
base, _ := tag.Base()
fmt.Println("language:", base)
}
EOF
go mod tidy
go run . yo-NGgo mod tidy downloads x/text and writes go.sum.
Check it worked
The program prints language: yo. ls ~/osv-demo/* lists pom.xml, requirements.txt, package.json and package-lock.json, and go.mod, go.sum and main.go.
Step 3 · Scan the whole repository in one pass
osv-scanner scan source scans source code; -r walks every subfolder and picks up each lockfile or manifest it recognises:
cd ~/osv-demo
osv-scanner scan source -r . || echo "osv-scanner exit code: $?"The scanner first lists each file it read, such as Scanned /home/<you>/osv-demo/web/package-lock.json file and found 1 package (with your home folder). Then comes a summary line and a table, something like:
Total 8 packages affected by 31 known vulnerabilities (3 Critical, 12 High, 16 Medium, 0 Low, 0 Unknown) from 4 ecosystems.
31 vulnerabilities can be fixed.
| OSV URL | CVSS | ECOSYSTEM | PACKAGE | VERSION | FIXED VERSION | SOURCE |
| https://osv.dev/GO-2021-0113 | 7.5 | Go | golang.org/x/text | 0.3.5 | 0.3.7 | worker/go.mod |
| https://osv.dev/GHSA-ppp9-7jff-5vj2 | | | | | | |
| https://osv.dev/GHSA-jfh8-c2jp-5v3q | 10.0 | Maven | org.apache.logging.log4j:log4j-core | 2.14.1 | 2.15.0 | billing/pom.xml |
| https://osv.dev/PYSEC-2023-74 | 6.1 | PyPI | requests | 2.25.0 | 2.31.0 | api/requirements.txt |
| https://osv.dev/GHSA-35jh-r3h4-6jhm | 7.2 | npm | lodash | 4.17.20 | 4.17.21 | web/package-lock.json |How to read a row:
- OSV URL opens the advisory. A row with only a URL is an alias: the same flaw under another database's ID (
GO-2021-0113from the Go database isGHSA-ppp9-7jff-5vj2in GitHub's). OSV groups aliases so one flaw counts once. - CVSS is the severity score from 0 to 10. An empty cell means the advisory has no score yet, not that it is harmless.
- FIXED VERSION is the lowest release that fixes that advisory.
--means there is no fix. - SOURCE is the file the package came from, so you know which team owns the finding.
Notice that the scan found more packages than you listed. requirements.txt named only requests, yet urllib3, idna and certifi appear: for requirements.txt and pom.xml, which are manifests rather than lockfiles, OSV-Scanner works out the transitive dependencies with Google's deps.dev service. It guesses the versions pip or Maven would pick today, so treat those rows as likely rather than certain. A fully pinned file from pip freeze or a real lockfile gives exact results. --no-resolve turns the guessing off.
The exit code tells scripts and CI what happened: 0 means packages were found and none is vulnerable, 1 means there are findings, and 128 means no package files were found at all (usually a wrong path). Here it is 1. The || echo keeps your shell going and shows the code. Files listed in .gitignore are skipped unless you add --no-ignore.
Check it worked
Save a JSON report and count findings per source file:
cd ~/osv-demo
osv-scanner scan source -r --format json --output-file ~/osv-report.json . || [ $? -eq 1 ]
jq -r '.results[] | "\(.source.path | sub(".*/osv-demo/"; "")) \([.packages[].groups[]] | length) findings"' ~/osv-report.json|| [ $? -eq 1 ] accepts exit code 1 (findings) but still fails on a real error. You get four lines, one each for web/package-lock.json, api/requirements.txt, worker/go.mod and billing/pom.xml, each with a number above zero. --format also accepts sarif for GitHub code scanning, markdown for a pull request comment, and cyclonedx-1-6 or spdx-2-3 for a software bill of materials.
Step 4 · See which Go findings your code calls
The table showed one advisory for golang.org/x/text, but x/text 0.3.5 has more than one. The other was hidden on purpose. For Go, OSV-Scanner runs call analysis by default: it builds your program's call graph with the Go toolchain and checks whether any path reaches the vulnerable functions named in each advisory. Findings your code cannot reach are moved out of the main table. Show them with --all-vulns:
cd ~/osv-demo
osv-scanner scan source --all-vulns worker || echo "osv-scanner exit code: $?"The table now has a second part under a row that reads Uncalled vulnerabilities:
| https://osv.dev/GO-2021-0113 | 7.5 | Go | golang.org/x/text | 0.3.5 | 0.3.7 | worker/go.mod |
| Uncalled vulnerabilities | | | | | | |
| https://osv.dev/GO-2022-1059 | 7.5 | Go | golang.org/x/text | 0.3.5 | 0.3.8 | worker/go.mod |GO-2021-0113 is a flaw in language.Parse, which main.go calls, so it stays on top. GO-2022-1059 is in language.ParseAcceptLanguage and MatchStrings, which the worker never calls. The JSON report records the verdict per advisory:
cd ~/osv-demo
osv-scanner scan source --format json --output-file ~/worker.json worker || [ $? -eq 1 ]
jq -r '.results[].packages[].groups[].experimental_analysis // {} | to_entries[] | "\(.key) called=\(.value.called)"' ~/worker.jsonHow far to trust "uncalled":
- It is a statement about today's code. The next commit that calls
ParseAcceptLanguagemakes the finding live, and the scan will say so then, which is why you keep scanning. - It depends on the advisory naming the affected functions. The Go database does this well; most other ecosystems do not, so npm, Python and Maven findings get no call analysis.
- Upgrade anyway when it is cheap. Uncalled findings are a reason to schedule the work, not to skip it.
The analysis needs go on your PATH and the module downloaded (go mod download or go mod tidy). Turn it off with --no-call-analysis=go, and every Go finding appears in the main table.
Check it worked
The jq output includes the lines GO-2021-0113 called=true and GO-2022-1059 called=false. Any newer x/text advisories also show called=false, since the worker uses only language.Parse.
Step 5 · Record an exception that expires
Sometimes you cannot fix a finding today and have decided the risk is acceptable for now. Write the decision down where the scanner reads it, with a reason and an end date, rather than letting the finding train everyone to ignore red output.
Take GHSA-9hjg-9r4m-mvj7: requests before 2.32.4 can send .netrc credentials to the wrong host. Suppose your API servers have no .netrc file and the upgrade is booked for next quarter. OSV-Scanner reads osv-scanner.toml from the same folder as the file it scans (it does not look in parent or child folders):
cat > ~/osv-demo/api/osv-scanner.toml <<EOF
[[IgnoredVulns]]
id = "GHSA-9hjg-9r4m-mvj7"
effectiveUntil = $(date -d '+60 days' +%F)
reason = "No .netrc on the API hosts. requests upgrade to 2.33 booked for next quarter (ticket SEC-142)."
EOF
cat ~/osv-demo/api/osv-scanner.toml
cd ~/osv-demo
osv-scanner scan source api 2>&1 | grep -E 'Loaded filter|filtered out' || trueThe unquoted EOF lets the shell fill in a date 60 days from today, so the example works whenever you run it. In a real project you write a fixed date, such as effectiveUntil = 2027-03-31, that matches the plan you agreed. effectiveUntil is the date the exception stops working. After it, the finding comes back and the build fails again, so nobody has to remember to review it. Ignoring an ID also ignores its aliases, here CVE-2024-47081 and PYSEC-2026-1872 on OSV.dev in November 2026. Replace the ticket reference with your own.
Keep exceptions specific: one ID, one reason, a date within a quarter. To share one file across folders, pass --config=path/to/osv-scanner.toml, which then replaces every per-folder file. For a whole package (an internal fork you patch yourself), [[PackageOverrides]] entries take a name, an ecosystem and vulnerability.ignore = true, with the same effectiveUntil and reason keys.
Check it worked
cat shows the file with a date about two months ahead. The scan output shows Loaded filter from: /home/<you>/osv-demo/api/osv-scanner.toml (with your home folder) and GHSA-9hjg-9r4m-mvj7 and 2 aliases have been filtered out because: followed by your reason. The other requests advisories still appear in the full table.
Step 6 · Fix the npm lockfile with guided remediation
For npm (and Maven), osv-scanner fix works out which upgrades remove the most findings and applies them. The in-place strategy edits package-lock.json directly, staying within the ranges package.json allows (^4.17.20 here, so any 4.x). It is marked experimental in the docs and may change between minor releases, so review its changes as you would a teammate's.
Work on a branch in a real project, and read the warning it prints first: on a project you do not trust, the fix command can follow registries named in the project.
cd ~/osv-demo/web
osv-scanner fix --strategy=in-place -L package-lock.jsonThe output ends with lines like:
Can fix 4/4 matching vulnerabilities by changing 1 dependencies
UPGRADED-PACKAGE: lodash,4.17.20,4.18.1
FIXED-VULN-IDS: GHSA-29mw-wpgm-hmr9,GHSA-35jh-r3h4-6jhm,GHSA-r5fr-rjxr-66jc,GHSA-xxjr-mmjv-4gpg
REMAINING-VULNS: 0The version and IDs depend on what lodash has published since. Next, in a real project, run npm ci and your tests, then commit the lockfile. Other strategies and options:
--strategy=relax -M package.json -L package-lock.jsonwidens the ranges inpackage.json(including to new major versions) and runs npm to rebuild the lockfile. Use it when the fix needs a version outside the current range.--upgrade-config=minor(orlodash:patch, per package) caps how far it may jump, so you control breaking changes.--ignore-devskips findings that come only fromdevDependencies.
Check it worked
grep -A1 '"node_modules/lodash"' package-lock.json
cd ~/osv-demo
osv-scanner scan source web || echo "osv-scanner exit code: $?"The lockfile shows a version above 4.17.20, and the scan of web ends with No issues found and exit code 0. If a newer lodash advisory has been published, you see it here instead.
Step 7 · Check licences against an allow-list
A dependency can be safe and still be a legal problem: a copyleft licence in a product you ship closed-source, or no licence at all. OSV-Scanner looks up each package's licence on deps.dev. With --licenses alone it prints a summary; with a comma-separated list of SPDX identifiers it reports every package whose licence is not on the list.
cd ~/osv-demo
osv-scanner scan source --licenses="MIT,Apache-2.0" web worker || echo "osv-scanner exit code: $?"After the vulnerability table come two more: a count per licence, and a LICENSE VIOLATION table:
| LICENSE VIOLATION | ECOSYSTEM | PACKAGE | VERSION | SOURCE |
| BSD-3-Clause | Go | golang.org/x/text | 0.3.5 | worker/go.mod |BSD-3-Clause is a permissive licence most companies accept, so the right response here is to add it to the list. The allow-list is your organisation's policy, not a technical setting; agree it with whoever signs off on licences. A non-standard entry means the package declares a licence that is not a standard SPDX identifier, and someone needs to read it.
Check it worked
osv-scanner scan source --licenses="MIT,Apache-2.0,BSD-3-Clause" web worker 2>&1 | grep -c 'LICENSE VIOLATION' || trueThe count is 0: with BSD-3-Clause allowed, the violations table is gone.
Step 8 · Scan offline for an air-gapped build
By default OSV-Scanner sends package names and versions to api.osv.dev. A build machine with no internet, or a policy against sending your dependency list out, needs the database on disk instead. --download-offline-databases fetches the database for each ecosystem it finds, and --offline-vulnerabilities checks against those local copies:
export OSV_SCANNER_LOCAL_DB_CACHE_DIRECTORY=~/osv-db
cd ~/osv-demo
osv-scanner scan source --offline-vulnerabilities --download-offline-databases worker || echo "osv-scanner exit code: $?"
du -sh ~/osv-dbThe environment variable picks the folder; without it the scanner uses your user cache folder. The Go database was about 13 MB in November 2026; the npm and Maven databases are many times larger, so on metered or prepaid data download them once on a fixed connection. Copy the folder to the air-gapped machine, set the same variable there, and scan with --offline, which uses only local data, sends nothing and fails if a database is missing:
osv-scanner scan source --offline worker || echo "osv-scanner exit code: $?"Two things change offline. Transitive resolution of requirements.txt and pom.xml is off, so only the packages named in the file are checked; lockfiles are unaffected. And the data is only as fresh as your last download, so refresh the folder on a schedule, daily for a build server.
Check it worked
The offline scan prints the same GO-2021-0113 row as the online one, and du shows the size of the saved database. When you have finished, remove everything this tutorial created:
cd ~
rm -rf ~/osv-demo ~/osv-db ~/osv-report.json ~/worker.json
unset OSV_SCANNER_LOCAL_DB_CACHE_DIRECTORYKeep /usr/local/bin/osv-scanner if you plan to use it; sudo rm /usr/local/bin/osv-scanner removes it. Go keeps the downloaded x/text module in its module cache; go clean -modcache clears it.
Next steps
- Go deeper on one ecosystem when its native tool gives you more: audit Node.js dependencies with npm audit and find vulnerable Python packages with pip-audit.
- Decide what to do with a long findings list, in order of real risk: triage security scanner findings.
- Vulnerable dependencies are one leak; committed keys are another. Scan a repository for leaked secrets with gitleaks.
Related tutorials
- Write custom Fail2ban jails and filters for your own appsYou will have Fail2ban 1.1 banning repeated failed sign-ins to your own app and to an nginx basic-auth area, with filters you tested against sample logs, your own addresses allow-listed, and longer bans for repeat offenders.
- Validate file uploads before you store or serve themYou will take a FastAPI image upload route that trusts everything the browser sends, prove its flaws with pytest, and rebuild it with size limits, type checks from the file's own bytes, Pillow re-encoding, random storage names and safe download headers.
- Use SSH certificates instead of copying keys to every serverYou will run a small SSH certificate authority with ssh-keygen, log in to an Ubuntu 26.04 server with an eight-hour user certificate, give the server a host certificate so clients stop asking about fingerprints, and revoke a certificate the server then refuses.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials