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

@middy/function-shield

v1.5.2

Published

Hardens AWS Lambda execution environment

Downloads

75

Readme

Middy FunctionShield middleware

⚠️ Warning: FunctionShield is no longer actively maintained and will unlikely be updated to have Node.js v12 support. See #460 ⚠️

Hardens AWS Lambda execution environment:

  • By monitoring (or blocking) outbound network traffic to public internet, you can be certain that your data is never leaked (traffic to AWS services is not affected)
  • By disabling read/write operations on the /tmp/ directory, you make sure that files are not persisted across invocations. Storing data in /tmp is a bad practice as it may be leaked in subsequent invocations
  • By disabling the ability to launch child processes, you can make sure that no rogue processes are spawned without your knowledge by potentially malicious packages
  • By disabling the ability to read the function's (handler) source code through the file system, you can prevent handler source code leakage, which is oftentimes the first step in a serverless attack

More info:

  • https://www.puresec.io/function-shield
  • https://www.jeremydaly.com/serverless-security-with-functionshield/

Get a free token

Please visit: https://www.puresec.io/function-shield-token-form

Modes

  • 'block' - Block and log to Cloudwatch Logs
  • 'alert' - Allow and log to Cloudwatch Logs
  • 'allow' - Allow

Options

  • policy.outbound_connectivity - 'block'/'alert'/'allow' (default: 'block')
  • policy.read_write_tmp - 'block'/'alert'/'allow' (default: 'block')
  • policy.create_child_process - 'block'/'alert'/'allow' (default: 'block')
  • policy.read_handler - 'block'/'alert'/'allow' (default: 'block')
  • token - By default looks for FUNCTION_SHIELD_TOKEN in process.env and context
  • disable_analytics - Periodically, during cold starts, FunctionShield sends basic analytics information to its backend. To disable analytics module set: true. (default: false)

Sample Usage

'use strict';

const fs = require('fs');
const middy = require('middy');
const {ssm, functionShield} = require('middy/middlewares');

async function hello(event) {
  fs.openSync('/tmp/test', 'w');
}


const handler = middy(hello)
  .use(ssm({
    cache: true,
    setToContext: true,
    names: {
      FUNCTION_SHIELD_TOKEN: 'function_shield_token'
    }
  }))
  .use(functionShield(
    {
      policy: {
        outbound_connectivity: 'alert'
      }
    }
  ));

module.exports = {
  handler
};
START RequestId: f7b7305d-d785-11e8-baf1-9136b5c7aa75 Version: $LATEST
[TOKEN VERIFICATION] license is OK
{"function_shield":true,"policy":"read_write_tmp","details":{"path":"/tmp/test"},"mode":"block"}
2018-10-24 15:11:45.427 (+03:00)        f7b7305d-d785-11e8-baf1-9136b5c7aa75    {"errorMessage":"Unknown system error -999: Unknown system error -999, open '/tmp/test'","errorType":"Error","stackTrace":["Object.fs.openSync (fs.js:646:18)","Function.hello (/var/task/handler.js:8:6)","runMiddlewares (/var/task/node_modules/middy/src/middy.js:180:42)","runNext (/var/task/node_modules/middy/src/middy.js:85:14)","before (/var/task/node_modules/middy/src/middlewares/functionShield.js:20:5)","runNext (/var/task/node_modules/middy/src/middy.js:70:24)","<anonymous>","process._tickDomainCallback (internal/process/next_tick.js:228:7)"]}
END RequestId: f7b7305d-d785-11e8-baf1-9136b5c7aa75
REPORT RequestId: f7b7305d-d785-11e8-baf1-9136b5c7aa75  Duration: 458.65 ms     Billed Duration: 500 ms         Memory Size: 1024 MB    Max Memory Used: 38 MB  

Middy documentation and examples

For more documentation and examples, refers to the main Middy monorepo on GitHub or Middy official website.

Contributing

Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.

License

Licensed under MIT License. Copyright (c) 2017-2018 Luciano Mammino and the Middy team.