Skip to content

pkgaudit: Static Analysis Security Testing (SAST) for R Packages #802

Description

@tylerjssmith

Submitting Author Name: Tyler Smith
Submitting Author Github Handle: @tylerjssmith
Repository: https://github.com/tylerjssmith/pkgaudit
Submission type: Pre-submission
Language: en


  • Paste the full DESCRIPTION file inside a code block below:
Package: pkgaudit
Title: Static Analysis Security Testing (SAST) for R Packages
Version: 0.4.0
Authors@R:
    person("Tyler", "Smith", , "tylerjssmith@gmail.com", role = c("aut", "cre"),
           comment = c(ORCID = "0000-0003-4692-2206"))
Description: A static analysis tool that flags security-relevant files and code
  in R source packages for human review without executing anything it scans.
  Models package lifecycle execution semantics -- it reports not just what a
  package does, but when it runs, so code that executes on install or load is
  distinguishable from code that runs only when called. Reads every surface a
  package can execute, including 'configure' scripts, help-file macros, and
  vignettes, and states what it could not read, so a clean result can be checked
  rather than trusted. Detection rules are data, shipped in a versioned and
  hash-verified 'SQLite' database.
License: Apache License (>= 2)
URL: https://github.com/tylerjssmith/pkgaudit,
    https://tylerjssmith.github.io/pkgaudit/
BugReports: https://github.com/tylerjssmith/pkgaudit/issues
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
Depends:
    R (>= 4.1)
Imports:
    DBI,
    digest,
    RSQLite,
    stats,
    tools,
    utils,
    xml2,
    xmlparsedata
Suggests:
    covr,
    jsonlite,
    knitr,
    rmarkdown,
    testthat (>= 3.0.0),
    yaml
VignetteBuilder: knitr
Config/testthat/edition: 3
Config/roxygen2/version: 8.1.0
Config/Needs/website: pkgdown
Config/Needs/coverage: covr

Scope

  • Please indicate which category or categories from our package fit policies or statistical package categories this package falls under. (Please check one or more appropriate boxes below):

    Data Lifecycle Packages

    • data retrieval
    • data extraction
    • data munging
    • data deposition
    • data validation and testing
    • workflow automation
    • version control
    • citation management and bibliometrics
    • scientific software wrappers
    • field and lab reproducibility tools
    • database software bindings
    • geospatial data
    • translation

    Statistical Packages

    • Bayesian and Monte Carlo Routines
    • Dimensionality Reduction, Clustering, and Unsupervised Learning
    • Machine Learning
    • Regression and Supervised Learning
    • Exploratory Data Analysis (EDA) and Summary Statistics
    • Spatial Analyses
    • Time Series Analyses
    • Probability Distributions
  • Explain how and why the package falls under these categories (briefly, 1-2 sentences). Please note any areas you are unsure of:

I have checked "data validation and testing" and "workflow automation" as the
nearest fits because pkgaudit is used to validate research inputs (R packages),
but security tooling is not an explicit category, and whether pkgaudit is in
scope is the main question of this inquiry.

When searching for prior art, I noted a previous effort to develop a tool like
this for rOpenSci -- defender --
and some discussions around the same time about rOpenSci security -- like this.
It has been several years, but I wondered if there is still interest a tool like
pkgaudit. If so, I would be happy to build it toward what is needed.

If pkgaudit is out of scope, I would appreciate suggestions for a better home.
Thanks for your consideration!

pkgaudit is not a statistical package.

  • Who is the target audience and what are scientific applications of this package?

Anyone who installs R packages from sources they have not read: individual
researchers, research software engineers and security professionals who approve
packages for regulated environments (e.g., clinical and pharmaceutical
statistical computing), and package repositories.

The scientific application is supply-chain security for the software science
runs on. R packages execute code in places reviewers rarely look -- configure
scripts at install, \Sexpr{} macros when help pages build, .onLoad() and
.onAttach(), and inline R in vignettes, for example. pkgaudit extracts this
code and scans it for security-relevant function calls and commands.

Rules have been tested at CRAN-scale (see dev/cran_survey). Every claim about
when in an R package lifecycle code may run is measured with instrumented
packages rather than taken from documentation (see dev/execution_surface).

To my knowledge, no R package does static security analysis of package source
code. The nearest neighbors solve different problems: oysteR and rosv check
package names and versions against known-vulnerability databases; riskmetric
(R Validation Hub) scores package risk from metadata and community metrics;
lintr and goodpractice assess code quality, not security.

Not applicable: pkgaudit reads package source code only and collects nothing.
It does not reach the network. Reports can omit local filesystem paths (path = FALSE)
so results can be shared without disclosing usernames or directory layouts.

  • Any other questions or issues we should be aware of?:

The package is designed with security in mind: it never executes what it scans
(asserted end-to-end by a test), tarball handling is fail-closed against
adversarial archives, and the rule database is reproducible byte-for-byte from
YAML sources and verified against a published SHA-256.

The biggest problem with static analysis of R is the dynamic nature of the
language. A partial solution in pkgaudit is searching not only for function
calls (e.g., system()) in an XML parse tree but also strings containing those
function names in metaprogramming functions (e.g., do.call("system")). Additional
suggestions for reducing this problem would be appreciated.

pkgaudit is not yet on CRAN; submission is planned, and I would prefer
rOpenSci review first if the package is in scope.

Use of Generative AI

  • Generative AI tools were used to produce some of the material in this submission.

Claude Code was used as a code-review and drafting assistant during development:
it performed pre-release reviews that surfaced bugs (which I verified and whose
fixes are covered by tests), and helped draft documentation and tests based on
my direction. All changes are reviewed, tested, and committed by me; the
detection rules and lifecycle-phase assignments are grounded in measurement
against instrumented packages and a survey of CRAN that anyone can replicate using
code I have provided (see dev/).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions