Site icon R-bloggers

Detecting Security Vulnerabilities in R Packages

[This article was first published on r – Jumping Rivers, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

< !-- output: md_document -->

One of our main roles at Jumping Rivers is to set-up and provide ongoing maintenance to R, Python and RStudio infrastructure. This typically involves ensuring software is up-to-date and making sure everything is running smoothly.

The OSS Index developed by Sonatype is a

free catalogue of open source components and scanning tools to help developers identify vulnerabilities, understand risk, and keep their software safe.

The {oysteR} package is an R interface to the OSS Index that allows users to scan their installed R packages. A few months ago, I stumbled across a fledgeling version of this package and decided to make a few contributions to help move the package from GitHub to CRAN. A few PRs later, I’m now a co-author and the package is on CRAN.

Installing the {oysteR} package is straightforward, just the usual install.packages() dance:

install.packages("oysteR")

After loading the package

library("oysteR")

We can audit the installed R packages for security vulnerabilities via the command

audit = audit_deps()

Which produces the output

# ℹ Calling installed.packages(), this may take time
#
# ── Calling sonatype API: https://www.sonatype.com/ ──
#
# → Using Sonatype tokens
# ℹ Calling API: batch 1 of 2
# ℹ Calling API: batch 2 of 2
#
# ── Vulnerability overview ──
#
# ℹ 218 packages were scanned
# ℹ 190 packages were in the Sonatype database
# ℹ 1 package contains known vulnerability
# ℹ A total of 1 known vulnerability was identified

As the output suggests, this function performs a few steps:

  1. Calls installed.packages() to determine the installed packages on your machine. Although there are warnings about this taking a little while, I’ve never had any issues.

  2. Splits the packages into batches of 128 and queries the Sonatype API. Note, I’ve registered for Sonatype to allow more API calls. This isn’t strictly necessary, but registering increases the number of API calls you can make – see the GitHub README.

  3. Summarises the results. In above, a total of 218 packages were scanned, at least 190 were found in the Sonatype database, and a single vulnerability was identified.

    Packages might not be on Sonatype for a variety of reasons. For example, you may have personal packages. In my case, I have a large number of Jumping Rivers teaching related packages.

The million-pound question is, what is the vulnerability? To obtain a few more results, we can use

get_vulnerabilities(audit)

which returns a tibble given further details. In our case, the vulnerable package is

{widgetframe}, version 0.3.1 (the current latest version)

After consulting the link provided by get_vulnerabilites(), we see that the issue

Vulnerabilities in R

Right now the few vulnerabilities that have been detected within R packages typically involve a Javascript library that has been included. However, it would be a bit hopeful to assume these are the only vulnerabilities around. To paraphrase Donald Trump, “if we don’t look, then we won’t find,” so it is likely that security issues exist in other packages that contain other code, e.g. C++. As R gets more popular, I suspect that it will receive more and more attention from people with nefarious intentions. Particularly, as we push dashboards and documents to the web.

Summary

Including Javascript is amazingly easy – see this recent great blogpost from Maëlle Salmon and Garrick Aden-Buie for an excellent discussion. However, when we bundle external code within our package, we now need to ensure that we update the package at regular intervals. This brings a few challenges:

Ultimately the final responsibility lies with users (or their organisations), who need to take responsibility for the packages they use.


Jumping Rivers are full service, RStudio certified partners. Part of our role is to offer support in RStudio Pro products – including security. If you use any RStudio Pro products, feel free to contact us (). We may be able to offer free support.


The post Detecting Security Vulnerabilities in R Packages appeared first on Jumping Rivers.

To leave a comment for the author, please follow the link and comment on their blog: r – Jumping Rivers.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.