npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@contrast/test-bench-utils

v3.37.0

Published

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

Downloads

507

Readme

@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: