GuardRails

GuardRails

  • Languages iconEnglish
    • 中文

›Javascript/TypeScript

Overview

  • Introduction
  • What is GuardRails
  • Getting started
  • Findings
  • Vulnerabilities
  • Configuration
  • Custom Engines
  • False Positives
  • Enforce Passing Checks
  • Build Status on Pull Requests
  • FAQ
  • Pricing
  • Glossary
  • Tools & Licenses

API

  • Usage Guide
  • Endpoints

Vulnerabilities

  • Introduction
  • General

    • Overview
    • Hard-Coded Secrets

    Apex

    • Overview
    • Insecure Access Control
    • Insecure Network Communication
    • Insecure Processing of Data
    • Insecure Use of Cryptography
    • Insecure Use of Language/Framework API
    • Insecure Use of SQL Queries

    C/C++

    • Overview
    • Insecure Access Control
    • Insecure File Management
    • Insecure Processing of Data
    • Insecure Use of Cryptography
    • Insecure Use of Dangerous Function

    Dotnet

    • Overview
    • Insecure Access Control
    • Insecure Configuration
    • Insecure File Management
    • Insecure Processing of Data
    • Insecure Use of Cryptography
    • Insecure Use of Dangerous Function
    • Insecure Use of SQL Queries
    • Using Vulnerable Libraries

    Elixir

    • Overview
    • Insecure Configuration
    • Insecure File Management
    • Insecure Processing of Data
    • Insecure Network Communication
    • Insecure Use of Dangerous Function
    • Insecure Use of Language/Framework API
    • Insecure Use of SQL Queries
    • Using Vulnerable Libraries

    Go

    • Overview
    • Insecure File Management
    • Insecure Network Communication
    • Insecure Processing of Data
    • Insecure Use of Cryptography
    • Insecure Use of Dangerous Function
    • Insecure Use of SQL Queries
    • Using Vulnerable Libraries

    Java

    • Overview
    • Using Vulnerable Libraries
    • Insecure Use of SQL Queries
    • Insecure Use of Dangerous Function
    • Insecure Use of Regular Expressions
    • Insecure Authentication
    • Insecure Configuration
    • Insecure File Management
    • Insecure Use of Cryptography
    • Insecure Use of Language/Framework API
    • Insecure Processing of Data
    • Insecure Network Communication

    Javascript/TypeScript

    • Overview
    • Insecure Authentication
    • Insecure Processing of Data
    • Insecure Use of SQL Queries
    • Insecure Use of Regular Expressions
    • Insecure Use of Language/Framework API
    • Insecure Use of Dangerous Function
    • Using Vulnerable Libraries

    Kubernetes

    • Overview
    • Insecure Access Control
    • Insecure Configuration
    • Insecure Network Communication

    PHP

    • Overview
    • Insecure Configuration
    • Insecure File Management
    • Insecure Network Communication
    • Insecure Processing of Data
    • Insecure Use of Dangerous Function
    • Insecure Use of Language/Framework API
    • Insecure Use of Regular Expressions
    • Insecure Use of SQL Queries
    • Using Vulnerable Libraries

    Python

    • Overview
    • Insecure Configuration
    • Insecure Use of Cryptography
    • Insecure Network Communication
    • Insecure Processing of Data
    • Insecure Use of Dangerous Function
    • Insecure Use of SQL Queries
    • Using Vulnerable Libraries

    Ruby

    • Overview
    • Insecure Access Control
    • Insecure Configuration
    • Insecure File Management
    • Insecure Network Communication
    • Insecure Processing of Data
    • Insecure Use of Dangerous Function
    • Insecure Use of Language/Framework API
    • Insecure Use of Regular Expressions
    • Insecure Use of SQL Queries
    • Using Vulnerable Libraries

    Rust

    • Overview
    • Using Vulnerable Libraries

    Solidity

    • Overview
    • Insecure Integer Arithmetic
    • Insecure Use of Low-Level Call
    • Reliance on Insecure Random Numbers
    • State Change After External Call
    • Transaction Order Dependence
    • Unprotected Critical Function
    • Use of Insecure Function
    • Dependence on Predictable Environment Variables
    • Write to Arbitrary Storage Location
    • Call to Untrusted Contract

    Terraform

    • Overview
    • Hard-Coded Secrets
    • Insecure Access Control
    • Insecure Configuration
    • Insecure Network Communication
    • Insecure Use of Cryptography

Insecure Use of Language/Framework API

This category covers the following Node.js APIs:

  • Buffer()

Insecure Use of Buffer()

Why is this important?

Node.js, like any other programming language, has dangerous functions. If these functions are not used properly, it can have a catastrophic impact on your app. The new Buffer() function can allow attackers to get full access to your production environment. The new Buffer() function has been deprecated since Node.js v6.0.0.

Read below to find out how to fix this issue in your code.

Fixing Insecure Use of new Buffer()

Option A: Replace new Buffer() with secure Buffer APIs

  1. Go through the issues that GuardRails identified in the PR.
  2. Replace new Buffer() with secure alternatives to achieve the same outcome. For example, use Buffer.from() or Buffer.alloc(). Two examples are shown below:
//Instead of this:
new Buffer(req.body.foo, "utf8");
new Buffer(req.body.length);

// Use this:
Buffer.from(req.body.foo, "utf8");
Buffer.alloc(req.body.length);
  1. Test it and ensure the functionality works as expected
  2. Ship it 🚢 and relax 🌴

Option B: Use Safe-Buffer

  1. Install Safe-Buffer.
npm install --save safe-buffer
  1. Add the following line to the top of your Node.js modules.
var Buffer = require("safe-buffer").Buffer;
  1. Test it and ensure your app is still working as expected.
  2. Ship it 🚢 and relax 🌴

More information:

  • Buffer is unsafe
  • Buffer Constructor Deprecation
  • Common Weakness Enumeration (CWE-201)*
  • Documentation of safe-buffer
  • Node.js Documentation of Buffer()
← Insecure Use of Regular ExpressionsInsecure Use of Dangerous Function →
  • Insecure Use of Buffer()
    • Why is this important?
    • Fixing Insecure Use of new Buffer()
    • More information:
  • Status
  • Help
  • Security
  • Terms
  • Privacy

© 2021 GuardRails