-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add security assessment via {oysteR} #272
base: master
Are you sure you want to change the base?
Changes from 10 commits
735029e
b8950b2
1816f07
d8bb71f
ba48a9a
20ce000
4bb0510
be63283
1b1eebe
2625d0f
1a7e7da
c81c54a
0eeafc4
07478e7
e18db11
45429cd
ebbecca
e9d5e25
b49af45
5c57b12
cac9499
2037deb
82e9090
6b73d22
14e6a50
3f5f9b8
9efd972
94e9fa0
4c23d2c
19ae89a
297a17e
66d73d1
96a14c6
1ae59ef
cac8ce0
4c7a013
8e98a05
8f13cf1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#' Assess a package for known security vulnerabilities in the OSS Index | ||
#' | ||
#' @param x a \code{pkg_ref} package reference object | ||
#' @param ... additional arguments passed on to S3 methods, rarely used | ||
#' @return a \code{pkg_metric} containing Assess for any known security vulnerabilities in the OSS Index via oysteR | ||
#' @seealso \code{\link{metric_score.pkg_metric_security}} | ||
#' | ||
#' @importFrom utils install.packages menu | ||
#' @export | ||
assess_security <- function(x, ...) { | ||
# TODO: discuss preferred approach for handling packages within Suggests | ||
if (!requireNamespace("oysteR", quietly = TRUE)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the version of oysteR they have installed matter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, more of a general question is if we need to create some tests for each new metric. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good catch. Addressed in 1a7e7da
A good discussion to have generally. I did plan on adding them for this metric once the |
||
if (interactive()) { | ||
inst_yn <- utils::menu( | ||
choices = c("Yes", "No"), | ||
title = paste( | ||
"Assessing security requires installation of the oysteR package.", | ||
"Would you like to install this now?" | ||
) | ||
) | ||
|
||
if (inst_yn == "1") { | ||
utils::install.packages("oysteR") | ||
} else { | ||
stop( | ||
paste( | ||
"asssess_security not run. Please install the oysteR package if you", " | ||
wish to assess security." | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
UseMethod("assess_security") | ||
} | ||
|
||
attributes(assess_security)$column_name <- "security" | ||
attributes(assess_security)$label <- "OSS Scan Results" | ||
attributes(assess_security)$suggests <- TRUE | ||
|
||
#' @export | ||
assess_security.default <- function(x, ...) { | ||
pkg_metric_eval(class = "pkg_metric_security", { | ||
x$security | ||
}) | ||
} | ||
|
||
|
||
#' Score a package for known security vulnerabilities in the OSS Index | ||
#' | ||
#' Coerce the count of reported vulnerabilities to a binary indicator. | ||
#' | ||
#' @eval roxygen_score_family("security", dontrun = TRUE) | ||
#' @return \code{1} if no vulnerabilities are found, otherwise \code{0} | ||
#' | ||
#' @export | ||
metric_score.pkg_metric_security <- function(x, ...) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we can capture the vulnerability overivew then we could set metric to |
||
as.numeric(x < 1) | ||
} | ||
attributes(metric_score.pkg_metric_security)$label <- | ||
"A binary indicator of whether a package has OSS Index listed vulnerabilities." |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for the ref_cache we should capture the oysteR output, if ony the tibble to start, but the entire message would be best (especially the overview).
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#' Run R CMD check and capture the results | ||
#' | ||
#' @inheritParams pkg_ref_cache | ||
#' @family package reference cache | ||
#' @return a \code{pkg_ref} object | ||
#' @keywords internal | ||
pkg_ref_cache.security <- function(x, ...) { | ||
UseMethod("pkg_ref_cache.security") | ||
} | ||
|
||
#' Check OSS Index lists any vulnerabilities for the package and it's | ||
#' dependencies | ||
#' | ||
#' @inheritParams pkg_ref_cache | ||
#' @return a \code{pkg_ref} object | ||
pkg_ref_cache.security.default <- function(x, ...) { | ||
|
||
# TODO: is this the right way to invoke the functionality to get this info? | ||
deps <- assess_dependencies(x) | ||
|
||
# when will this break? is as_pkg_metric_na? | ||
dep_names <- sapply(strsplit(deps[["package"]], " "), "[[", 1) | ||
|
||
# is this the best way to get relevant versions? | ||
bundle_ref <- pkg_ref(c(x$name, dep_names), source = x$source) | ||
bundle_names <- sapply(bundle_ref, "[[", "name") | ||
bundle_versions <- sapply(bundle_ref, function(r) as.character(r[["version"]])) | ||
|
||
scan_results <- oysteR::audit( | ||
pkg = bundle_names, | ||
version = bundle_versions, | ||
type = "cran", | ||
verbose = FALSE | ||
) | ||
|
||
return(sum(scan_results[["no_of_vulnerabilities"]])) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the assessment should be the tibble or possibly the list of vulnerabilities found. and then metric can be binary or presence/absence of vulnerabilities.