Safeguard
Security Guides•

Does deleting dead code reduce vulnerability findings in a legacy app?

Deleting dead code and unused dependencies removes findings at the source. Here is how to find what is safe to delete in a legacy app and verify it.

Safeguard Security Team
3 min read

Yes. When you delete code and the libraries only it used, the findings tied to those libraries disappear, with no patching. It is often the cheapest fix in a legacy application, provided you prove the code is really unused before removing it.

Why legacy apps carry so much dead weight

Systems that have grown over many years collect features nobody uses, abandoned modules and libraries that remain in build files after the code that needed them left. Fowler notes that much of what a legacy system does is behavior that is not really wanted. A scanner does not know that. It reports every vulnerable component in the build, used or not.

Three kinds of removable weight

  1. Unused dependencies. Declared in the build, never imported.
  2. Dead modules. Compiled and packaged, but no route, job or caller reaches them.
  3. Dead features. Reachable in theory, but no user has touched them in a long time.

How to find them, safely

  1. Static analysis for unused imports and modules. Most build tools can report declared but unused dependencies.
  2. Reachability analysis. Flag vulnerable libraries whose vulnerable functions are never called. This points to candidates, though it does not prove a library can go.
  3. Runtime evidence. Check access logs, job schedules and metrics for the feature over a full business cycle, including month end and year end jobs.
  4. Ask owners. A short message to the owning team and to support often turns up a known customer.
EvidenceConfidence the code is dead
No import foundMedium, reflection can hide use
No route or schedule reaches itMedium to high
No logged use over a full cycleHigh
Owner confirmsHigh

How to remove it with a way back

  1. Put the feature behind a flag set to off, and watch for errors.
  2. Remove the code and the dependency in separate commits.
  3. Rebuild and rerun tests.
  4. Rescan and compare to the baseline.
  5. Keep the version control history so you can restore it.

The strangler facade helps here. If a route was never used, retire the route at the facade first. Requests that fail loudly tell you quickly whether someone needed it.

What to expect afterward

The count of findings drops, and the attack surface drops with it, because code that is gone cannot be exploited. Record the before and after numbers for your modernization report. See security findings in legacy code nobody owns for handling modules with no owner.

Try it yourself

Click through it at your own pace, or open it full screen.

See which findings sit in code that is never called. Those are your first deletion candidates, subject to the runtime checks above.

Safeguard's reachability analysis and dependency scanning can produce that candidate list, and the free scan at gold.safeguard.sh/scan is a quick start.

Quick check

Is unreachable code safe to leave in place?

It is lower risk, but it still adds findings and attack surface, and reachability can change with a later edit. Deleting it is better.

Can reflection hide usage?

Yes. Static analysis can miss code called by name at runtime, so back it with runtime evidence.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.