Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contrast/test-bench-utils

Package Overview
Dependencies
Maintainers
0
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contrast/test-bench-utils

Shared code to use in Contrast's web framework test apps. Test

  • 3.37.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@contrast/test-bench-utils npm (scoped)

Shared code for use in Contrast's Node.js test apps.

Adding a shared sink

Under lib/routes.js, create a sink definition with the following form:

  [ruleName: string]: {
    base: string,                    // '/cmdInjection',
    name: string,                    // 'Command Injection',
    link: string,                    // 'https://www.owasp.org/index.php/Command_Injection',
    products: string[],              // ['Assess', 'Protect'],
    inputs: string[],                // ['query'],
    params: string[],                // ['input'],
    sinks: Object<string, Function>, // sinks.commmandInjection
  }

Then create a file under lib/sinks/ that exports functions with a consistent signature:

  /**
   * @param {Object} params the parameter object including provided user inputs.
   *   The `params` key from _routes.js_ determines which parameters will be
   *   extracted from the request object.
   * @param {Object} opts
   * @param {boolean} [opts.safe] are we calling the sink safely?
   * @param {boolean} [opts.noop] are we calling the sink as a noop?
   */
  module.exports['sinkName'] = async function sink({ input }, { safe = false, noop = false } = {}) { /* ... */ };

The sink function will be called by the endpoint handler appropriately by each framework. By default, for the /unsafe endpoint the function is called with user input, and for the /safe and /noop endpoints it is called with the safe and noop options set to true, respectively.

If providing more than one "safe" or "unsafe" pattern, you can export an object rather than a single function. This is done using the following pattern:

  module.exports['sinkName'] = {
    async safeOne({ input }) { /* ... */ },
    async safeTwo({ input }) { /* ... */ },
    async unsafeOne({ input }) { /* ... */ },
    async unsafeTwo({ input }) { /* ... */ },
    async noop() { return 'NOOP' },
  }

There's nothing tying you to the existing safe and unsafe method names when providing an object, so please provide meaningful function names. Routes will be generated with the function name as the last part of the path. Existing views assume the methods are safe, unsafe, and noop, but accounting for additional endpoints will require changes to views for the time being.

Front-end content

If there is any custom data you want to provide to the test bench front end, you can export it from lib/content/. For example, we export the following XML string as a potential attack for the xpath injection rule:

lib/content/xpathInjection.js

module.exports.xml = `
<?xml version="1.0"?>
<users>
  <user>
    <username>admin</username>
    <password>admin</password>
  </user>
  <user>
    <username>user1</username>
    <password>123456</password>
  </user>
  <user>
    <username>tony</username>
    <password>ynot</password>
  </user>
</users>
`;

This string is then used by the xpathInjection.ejs view in @contrast/test-bench-utils to render an input prepopulated with the attack value.

Adding a shared view

Once you have configured a sink you're ready to add a shared view. Shared view templates are rendered with the following locals provided:

  • name: the name of the vulnerability being tested
  • link: a link to OWASP or another reference describing the vulnerability
  • sinkData: an array of objects describing the sinks exercising a rule, containing (at least) the following keys:
    • method: the HTTP method being used to submit the attack
    • name: the name of the particular sink being exercised
    • url: the api endpoint url to hit
  • _csrf for Kraken apps, we provide the csrf token to be included as a hidden field within a form

An endpoint may also be configured to provide additional locals to the template to render additional context for a rule. For example, we provide an XML string to the xpathInjection endpoint as a potential attack value.

Test Bench Applications

Once you have configured the shared sink and view, consult the following instructions for including the shared functionality in each test bench app:

FAQs

Package last updated on 22 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc