Skip to main content

Use of software with known vulnerabilities

Need

Updating software and dependencies to address known vulnerabilities

Context

  • Usage of Dart for building cross-platform mobile, web, and desktop applications
  • Usage of Shelf for managing and organizing data in a Node.js application
  • Usage of shelf_io for managing and organizing data storage in a Node.js application

Description

Non compliant code

import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as io;

void main() {
var handler = const shelf.Pipeline()
.addMiddleware(shelf.logRequests())
.addHandler(_echoRequest);

io.serve(handler, 'localhost', 8080);
}

shelf.Response _echoRequest(shelf.Request request) {
return shelf.Response.ok('Request for "${request.url}"');
}

This Dart code is a basic example of a backend application using the Shelf web server middleware for Dart. The application listens for HTTP requests on port 8080 and responds with a simple message.

The vulnerability in this code lies in the use of an outdated or insecure version of the Shelf library. If the version of Shelf that's being used has known security vulnerabilities, then this code is vulnerable to those same threats. This could include issues like denial of service attacks, unauthorized data access, or data corruption.

To ensure the application is secure, it's necessary to always use the most recent and secure version of any libraries or dependencies. This includes regularly checking for and installing updates, and reviewing any security advisories or vulnerability reports related to the software you're using.

Steps

  • Identify the software or dependencies with known vulnerabilities. In this case, it could be the 'shelf' package.
  • Check the version of the vulnerable software or dependency being used. This can be found in the 'pubspec.yaml' file in Dart projects.
  • Look up the latest version of the software or dependency, or a version that has patched the known vulnerabilities. This can be found in the official documentation or repository of the software or dependency.
  • Update the software or dependency to the secure version. This can be done by changing the version number in the 'pubspec.yaml' file and running 'pub get' to fetch the updated package.
  • Test the application after updating the software or dependency to ensure it still works as expected.
  • Regularly update the software or dependencies to their latest versions to prevent using software with known vulnerabilities.

Compliant code

import 'package:shelf/shelf.dart' as shelf;
import 'package:shelf/shelf_io.dart' as io;

void main() {
var handler = const shelf.Pipeline()
.addMiddleware(shelf.logRequests())
.addHandler(_echoRequest);

io.serve(handler, 'localhost', 8080);
}

shelf.Response _echoRequest(shelf.Request request) {
return shelf.Response.ok('Request for "${request.url}"');
}

The above code is a simple backend application written in Dart using the Shelf framework. It sets up a server that listens on localhost at port 8080 and responds to all requests with a message containing the requested URL.

However, the code has a potential vulnerability if the version of the Shelf package being used has known vulnerabilities. Using software or dependencies with known vulnerabilities can expose the application to potential attacks, as attackers can exploit these known vulnerabilities to compromise the system.

To fix this vulnerability, we need to ensure that we are using a secure version of the Shelf package. This can be done by checking the version of the Shelf package in the 'pubspec.yaml' file, looking up the latest version or a version that has patched the known vulnerabilities, and updating the 'pubspec.yaml' file to use the secure version. After updating the package, we should run 'pub get' to fetch the updated package and test the application to ensure it still works as expected.

Regularly updating the software or dependencies to their latest versions is a good practice to prevent using software with known vulnerabilities.

References