Skip to Content
All Posts

How to scan source code you didn't write before you run it

· Zero to Hundred

To scan source code you didn't write, open it somewhere it can't reach your real accounts, install it with scripts switched off, then run 4 scans. Look for secrets with gitleaks or TruffleHog, known-vulnerable dependencies with npm audit or OSV-Scanner, dependency licenses with pnpm licenses or OSV-Scanner, and risky code patterns with Semgrep. Each tool catches one kind of problem. None of them tells you whether the app's permission rules are right.

This is the first hour with a codebase you bought, inherited from another team, or downloaded for client work. If you're still deciding whether to buy, use the purchase checklist first. This post starts once the files are on your machine.

What can run the moment you open or install the code?

Two things can run code before you've read any: your editor and your package manager. Both can be told to wait.

Your editor. VS Code can run a task automatically when you open a folder, if .vscode/tasks.json sets "runOn": "folderOpen". VS Code's tasks guide says automatic tasks never run in an untrusted workspace. Workspace Trust opens unfamiliar folders in Restricted Mode, which disables or limits the terminal, tasks, debugging, workspace settings and extensions. When VS Code asks whether you trust the authors, say no, and read .vscode/ before you change that.

Your package manager. A bare npm install runs the project's own preinstall, install, postinstall and prepare scripts, according to npm's scripts documentation. Dependencies are a separate question, and the answer depends on the version:

  • npm 12 blocks dependency install scripts unless the package is listed in the allowScripts field of package.json.
  • Older npm releases differ, and npm 11's docs aren't consistent on the default. Run npm --version and don't assume dependency scripts are blocked.
  • pnpm 12 blocks unapproved dependency build scripts by default, and strictDepBuilds, on by default, makes the install fail when it meets an unreviewed one. Approvals live in allowBuilds or permissions in pnpm-workspace.yaml, and dangerouslyAllowAllBuilds approves every build that isn't explicitly denied.

Those approval settings travel with the repo. A delivered package.json or pnpm-workspace.yaml can already approve scripts that whoever wrote it chose to run, so read both files before you install.

Skip package lifecycle scripts on the first install:

npm install --ignore-scripts

With ignore-scripts set, npm doesn't run scripts from package.json files. Commands that name a script, such as npm start, npm test and npm run, still run that script. In pnpm, the ignoreScripts setting skips lifecycle scripts in the project's package.json and its dependencies. A .pnpmfile.cjs or .pnpmfile.mjs hook file is separate, so also set ignorePnpmfile to true for the first install.

Where should you do the first install and scan?

Do it in a throwaway container or virtual machine that holds none of your real credentials. That means no SSH keys, no signed-in cloud command-line tools, no .env files from other projects, and no browser sessions. Keeping real credentials out of that environment limits what misbehaving code can reach.

Docker gives you two useful switches. The --rm flag removes the container and its anonymous volumes when it exits. --network none leaves the container with only a loopback device, so nothing inside can call out.

Cutting the network has a cost. The install itself and npm audit need to reach the internet. OSV-Scanner can work offline only if you download its databases first. A workable order is to install with scripts off while the network is on, then cut the network before you run or build anything from the project.

How do you find secrets, including in git history?

Run a secret scanner over the files and, if the delivery includes a .git folder, over every commit. A key deleted in a later commit is still in the history.

Gitleaks handles both. Its git command reads patches from git log -p, so it sees old commits. Its dir command scans the files in a folder, which is all you can do with a zip that has no history. The --redact flag keeps found secrets out of the terminal output and logs.

gitleaks git -v --redact .
gitleaks dir -v --redact path/to/project

TruffleHog scans the same places with trufflehog git file://. and trufflehog filesystem path/to/project. For secrets it can classify, it can log in to the provider to check whether the key still works. That check sends the key to the provider. Add --no-verification if you don't want it to.

A found key needs rotating, and deleting it from the code doesn't fix anything. GitHub's guide to leaked secrets says to treat any leaked secret as compromised right away and revoke it. It also says removing it from the code, pushing a new commit, or recreating the repository doesn't stop it being used. If the key belongs to the person who sent you the code, tell them so they can revoke it. Don't use it. Create your own key for every service the app needs.

How do you check dependencies for known vulnerabilities?

Check that a lockfile came with the code, then run npm audit or OSV-Scanner against it. Both match the exact dependency versions against published advisories.

The lockfile matters because it pins those versions. npm's lockfile documentation says package-lock.json describes the exact tree, so later installs produce the same one. Without it you're auditing whatever versions resolve today, which may not be what the author built and tested. npm audit needs a package lock by default. Bypassing it means the results can change on every run.

Know what npm audit sends. It posts the name and version of every package in the tree to your default registry. If that request fails, npm falls back to a slower endpoint that also receives your npm version, Node.js version, platform, architecture and NODE_ENV. npm install also submits an audit by default, since the audit setting defaults to true. Don't reach for npm audit fix --force on code you haven't read yet. The force option lets audit fix install versions outside the stated ranges, including major-version changes.

OSV-Scanner checks the same lockfile against the OSV database. It can also run offline against databases you download first:

osv-scanner scan -r ./my-project-dir/
osv-scanner --offline-vulnerabilities --download-offline-databases ./my-project-dir/

Both tools report known advisories. A flaw nobody has published an advisory for won't show up.

How do you list dependency licenses, and why does copyleft matter?

List every dependency's license before you ship, and look for copyleft licenses such as the GPL and AGPL. They attach conditions to how you release the software that uses them.

Two documented ways to get the list:

osv-scanner --licenses path/to/repository
pnpm licenses list --prod

OSV-Scanner's license scan pulls license data from the deps.dev API. If you pass it a list of allowed standard license identifiers, it also reports the packages that fall outside it. In a pnpm project, pnpm licenses list reports the licenses of installed packages. --prod limits it to production dependencies and --json gives you a file you can keep.

Here's what the license authors say. The GNU GPL FAQ says you can modify GPL code and use it privately, inside a company too, without releasing it. Once you release the modified version to the public, you must make its source available to its users under the GPL. The same FAQ says that linking a GPL library means releasing your program under a GPL-compatible license.

The GNU AGPL goes further for web apps. Its preamble notes that the GPL lets you run a modified version on a server without releasing the source. Section 13 of the AGPL closes that gap. If you modify the program, your version must offer everyone who uses it over a network a way to get its source.

For agency work this decides what you can hand a client and on what terms. The scanner names the licenses. It can't tell you whether your use complies, so take a specific case to a lawyer.

How do you scan for risky code patterns?

Run a pattern scanner such as Semgrep for known risky patterns, such as SQL injection, and treat what it finds as leads to read. It won't check whether the app's authorization logic is right.

Semgrep is an open-source static analysis tool. Its CLI guide recommends semgrep scan for scanning a local codebase when you don't have a Semgrep account. The README says it analyzes code on your machine and doesn't upload code by default. If you pull rules from the Semgrep Registry, they report pseudonymous rule metrics to Semgrep. The README says --metrics=off turns that off.

semgrep scan

The free Community Edition has a stated limit. In security use it misses many real problems, because it only analyzes code inside a single function or file.

The wider limit applies to pattern scanners in general. The Open Worldwide Application Security Project's page on source code analysis tools lists authentication problems and access control issues as hard to automate. It also notes that these tools produce many false positives and often miss configuration problems, which aren't in the code. A clean scan can still hide a route that shows one user's records to another. Check that by hand with two accounts: test app permissions before launch walks through it.

What does each scan catch and miss?

Each scan answers one narrow question. Use this table to see what's still open after you've run them all.

CheckToolWhat it catchesWhat it misses
Editor auto-runVS Code Restricted ModeTasks set to run on folder open, workspace settings, extensionsAnything you run yourself after you trust the folder
Install scripts--ignore-scripts, allowScripts, allowBuildsScripts that would run during installScripts you start by name, such as npm start or npm test
Secrets in filesgitleaks dir, trufflehog filesystemKeys and tokens in the delivered filesKeys that exist only in git history
Secrets in historygitleaks git, trufflehog gitKeys in any commit you receivedHistory that wasn't delivered
Known vulnerabilitiesnpm audit, OSV-ScannerDependency versions with published advisoriesFlaws with no advisory. Without a lockfile, results can change between runs
Dependency licensesosv-scanner --licenses, pnpm licenses listThe license each dependency declaresWhether your use meets that license's terms
Risky code patternsSemgrepCode matching its rulesAuthorization logic, configuration, and in Community Edition anything spanning files

If a Builder is preparing code for someone else, the same list works in reverse. Name every install script and why it's there in the handoff README, and say whether git history is included.

How does this fit buying on Zero to Hundred?

When you buy on the marketplace, you get the source code as soon as you pay. Every sale is final.

You have 24 hours after delivery to report a factual problem: misrepresentation, a bug that stops it working, or another factual ground. Something the listing already disclosed doesn't count. The Builder's payout is held for 72 hours, so a report made in time is reviewed before they're paid.

So set up the container and install the scanners before you pay, and run them as soon as the files arrive. For a Next.js and Supabase app, pair these scans with the Next.js and Supabase checklist, which covers keys, migrations and Row Level Security.