Skip to content

Commit

Permalink
Start on override strategy for maven guided remediation (#1025)
Browse files Browse the repository at this point in the history
Start on a new 'override' remediation strategy for guided remediation
for maven, intending to remediate by forcing the use of non-vulnerable
versions by `dependencyManagement`.

This is just the logic to identify possible override patches by
searching for the first non-vulnerable version of an affected package.
  • Loading branch information
michaelkedar authored Jul 12, 2024
1 parent 9ab83d0 commit 56c68b8
Show file tree
Hide file tree
Showing 15 changed files with 80,767 additions and 411 deletions.
6 changes: 6 additions & 0 deletions cmd/osv-scanner/fix/interactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ package fix

import (
"context"
"errors"

tea "github.com/charmbracelet/bubbletea"
"github.com/google/osv-scanner/internal/remediation"
)

// TODO: currently, it's impossible to undo commands
// Need to think about how to support this

func interactiveMode(ctx context.Context, opts osvFixOptions) error {
if !remediation.SupportsRelax(opts.ManifestRW) && !remediation.SupportsInPlace(opts.LockfileRW) {
return errors.New("no supported remediation strategies found")
}

cl := opts.Client
p := tea.NewProgram(newModel(ctx, opts, cl), tea.WithAltScreen())
m, err := p.Run()
Expand Down
9 changes: 9 additions & 0 deletions cmd/osv-scanner/fix/noninteractive.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fix

import (
"context"
"errors"
"fmt"
"os"
"slices"
Expand All @@ -17,6 +18,10 @@ import (
)

func autoInPlace(ctx context.Context, r reporter.Reporter, opts osvFixOptions, maxUpgrades int) error {
if !remediation.SupportsInPlace(opts.LockfileRW) {
return errors.New("in-place strategy is not supported for lockfile")
}

r.Infof("Scanning %s...\n", opts.Lockfile)
f, err := lockfile.OpenLocalDepFile(opts.Lockfile)
if err != nil {
Expand Down Expand Up @@ -92,6 +97,10 @@ func autoChooseInPlacePatches(res remediation.InPlaceResult, maxUpgrades int) ([
}

func autoRelock(ctx context.Context, r reporter.Reporter, opts osvFixOptions, maxUpgrades int) error {
if !remediation.SupportsRelax(opts.ManifestRW) {
return errors.New("relock strategy is not supported for manifest")
}

r.Infof("Resolving %s...\n", opts.Manifest)
f, err := lockfile.OpenLocalDepFile(opts.Manifest)
if err != nil {
Expand Down
265 changes: 0 additions & 265 deletions internal/remediation/__snapshots__/relax_test.snap

This file was deleted.

Loading

0 comments on commit 56c68b8

Please sign in to comment.