Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What security guidance would be most useful for Node.js developers? #488

Closed
MarcinHoppe opened this issue Feb 9, 2019 · 34 comments
Closed
Assignees
Labels

Comments

@MarcinHoppe
Copy link
Contributor

MarcinHoppe commented Feb 9, 2019

Background

Currently the Guides section of the Node.js documentation does not have any documentation around security. I think it's fair to say that such guidance would be a useful and welcome addition to the documentation.

Based on my experience there are two target groups for such guidance: programmers working on Node.js applications and application security engineers supporting Node.js applications. I think the focus here should be on the first group.

The second group already has a very useful resource in the form of Node.js Security Roadmap. See #101 for background on this document.

This issue was inspired by #478.

Expected outcome

I would like to use this issue to solicit input both from the Security Working Group as well as from the broader Node.js community. An ideal outcome would be a list of security aspects to take into account when writing Node.js programs that we could turn into guides or a set of guides on the Node.js website.

Scope

Ideally, the guidance should be limited to the JavaScript programming techniques, the Node.js runtime and its core libraries.

How to move forward

If you have an idea, describe it and post as a comment under this issue. If you like an already existing idea, use 👍 to express support. This way we can gauge the demand for guidance on a given aspect.

@MarcinHoppe
Copy link
Contributor Author

Idea 1: Managing dependencies to minimize the attack surface and make upgrading vulnerable dependencies a manageable problem.

@MarcinHoppe
Copy link
Contributor Author

Idea 2: working with regular expressions to avoid Regular Expression Denial of Service (ReDoS) attacks.

@MarcinHoppe
Copy link
Contributor Author

Idea 3: working with filenames and paths in a secure way to avoid Path Traversal attacks and similar.

@shivasurya
Copy link

Idea 4: logging the errors to log management and preventing complete stacktrace printing in the response

@shivasurya
Copy link

idea 5: use the whitelist variables/names for the server-side rendering/template of data that can reduce RCE/LFI attacks

@shivasurya
Copy link

idea 6:

  • Use regex ( safer regex ) and datatype validation as middleware before reaching the routes
  • using appropriate content-type for rendering data in frontend
  • use helmet npm to add relevant security headers by default to all response

@MarcinHoppe
Copy link
Contributor Author

@shivasurya Thanks for those ideas! Is there a way to narrow them down so that we don't go into the details of specific libraries and frameworks? I strongly believe the guidance on the official Node.js site should be limited to JavaScript itself, the Node.js runtime and its core libraries.

@rikaardhosein
Copy link

Idea 7: How to execute external binaries/scripts with user-controlled arguments safely.

eg. execFile vs exec

@rikaardhosein
Copy link

Idea 8: How to safely craft user-influenced HTTP requests. (Prevent SSRF vulns, etc)

@shivasurya
Copy link

@MarcinHoppe I'll stick to the core lib and runtime and share possible ideas

@shivasurya
Copy link

@rikaardhosein Idea 8 remains me of this pdf
https://www.blackhat.com/docs/us-17/thursday/us-17-Tsai-A-New-Era-Of-SSRF-Exploiting-URL-Parser-In-Trending-Programming-Languages.pdf

Where node.js has been mentioned by Orange abusing URL parser and Unicode failure. Just bringing to the notice and how can we mitigate such attacks or fuzz vectors.

@MarcinHoppe sorry for going more detailed, but what do you think about this?

@bnb
Copy link
Contributor

bnb commented Feb 12, 2019

I strongly believe the guidance on the official Node.js site should be limited to JavaScript itself, the Node.js runtime and its core libraries.

I would love to better understand your opposition to this!

The Website Redesign initiative work currently going on around Guides is taking the opposite stance, fwiw.

@bnb
Copy link
Contributor

bnb commented Feb 12, 2019

Suggestions:

  • Automatically updating your dependencies
  • Monitoring for known vulnerabilities in CI/CD
  • Updating your runtimes to the minimum secure versions

@devansvd
Copy link

  • Fine tune validation for user inputs.

@MarcinHoppe
Copy link
Contributor Author

@bnb My take on:

I would love to better understand your opposition to this!

is about controlling the scope, primarily. I feel that we should not go into general (Web) security guidance because there are more authoritative sources (e.g. OWASP) and I am not even sure if we should dive into security aspects of specific frameworks (e.g. Express). I feel that documentation for libraries and frameworks are better suited to deliver this kind of guidance.

I am happy to be convinced otherwise on both fronts.

The Website Redesign initiative work currently going on around Guides is taking the opposite stance, fwiw.

I would love to know more about that. I will ping you directly.

@radekk
Copy link

radekk commented Feb 13, 2019

Idea 9: Cryptography guidelines

  • Working with secure random values (RNG)
  • Secure checks for initialisation vectors (IVs)
  • Working with passwords (bcrypt, scrypt, pbkdf2, salting etc.)
  • Timing attacks (side-channel)

Idea 10: Node.js event loop security [1]

refs:
[1] https://nodejs.org/en/docs/guides/dont-block-the-event-loop/ - it's really comprehensive guide but from the security perspective it could be useful to capture the essence of that text.

@bnb
Copy link
Contributor

bnb commented Feb 15, 2019

@MarcinHoppe not-so-brief response:

I would love to know more about that. I will ping you directly.
It'll be helpful if I answer this first.

Basically, what we've been doing with the Guides section is approaching it as "How would you use Node.js in the real world?" At this point, this means you're using libraries, tools, CLIs, and services that are explicitly outside of Node.js core, but are effectively needed in the modern Node.js workflows to do anything. You're probably not going to be hosting your FaaS on a PC under your desk or rolling your own authentication tooling, for example... and if you are doing that at scale, it would be awesome to share how to do that with others 😅

This is something I've personally been pushing us toward. If you look at our contributor base, we're all passionate about certain technologies are are writing guides about Node.js as a project independently of Node.js. We all have expertise in various scenarios that others don't. I take the stance that we should be leveraging our community and providing a source of education for our ecosystem about real-world Node.js.

One key piece of this is that it's neutral, not agnostic.

  • If someone wants to write guides about how to monitor Node.js with { Dynatrace || DataDog || Elastic || KeyMetrics || N|Solid }, they can.
  • If someone wants to write about how to manage Node.js versions with { nvm || nvs || fnm || n }, they can.
  • If someone wants to write about how to deploy Node.js to production with { AWS || OpenShift || Heroku || IBM Cloud || ZEIT Now || GCP || Netlify || Azure }, they can.
  • If someone wants to write about how to addres vulnerabilities with { npm audit || Snyk || BlackDuck || Source Clear }, they can.

This has been done very intentionally. Who is better motivated and able to write from a place of expertise around Node.js + ${x} than the people who work on and maintain these platforms and projects?

Okay, now for the response to your response 😅

is about controlling the scope, primarily. I feel that we should not go into general (Web) security guidance because there are more authoritative sources (e.g. OWASP)

Definitely get where you're coming from here – it's certainly aligned with The Node.js Way™️ and how our ecosystem has built itself up successfully, I think.

I am not even sure if we should dive into security aspects of specific frameworks (e.g. Express).

I get where you're coming from with this. However, the place we've been coming from in the Website Redesign Initiative has been the opposite. The first thing you ask someone who is using Express – which means they're also using Node.js – is "are you using Helmet?" Even though this is something about Express, it still ends up deeply involving Node.js and reflecting on us. Providing a space for this content is – IMO – a good approach.

@oke-py
Copy link

oke-py commented Feb 16, 2019

idea: managing dependencies guideline:
run npm audit, npm audit fix locally and/or CI to find and address vulnerabilities.

@mhdawson
Copy link
Member

In terms of scope I think there are a couple of considerations:

  1. keeping it manageable to start. This could mean that we start with a tighter focus but only to focus work not exclude content that might be added later

  2. Avoiding overlap with existing authoritative sources. If there is a good source covering a particular area then avoiding duplication of conflicting guidance would be good. On the other hand if there is no existing source then I think expanding into areas that are important for the success of Node.js and the JS ecosystem (ex express) makes sense to me.

@MarcinHoppe
Copy link
Contributor Author

@bnb as we discussed privately, thanks for filling my gaps on the Website Redesign initiative. I think it makes a lot of sense to follow the same spirit. This is good news because we can provide broader guidance that way.

Now, getting back to @mhdawson’s point, I think keeping focus initially on JS, Node.js runtime and core libraries as a starting point will help keep the scope under control. We will be able to branch out later on.

@nodejs/security-wg I would love to hear your feedack about the plan.

Next step is for me to collect the submitted ideas and rank them based on community feedback (exact mechanism is TBD) and statistics from our ecosystem H1 program and possibly other sources that are willing to share Node.js vulnerability data.

@Horaddrim
Copy link

OWASP itself have a cool section about some general guidelines on web security, so I really think that we should not overlap this sources, but at the same time, I love they format, of having a variety range of documents, where there are some of them really raw and generalistic (e.g The Top 10 project), and some of them really specific (e.g JWT best pratices in Java's Spring Boot), so, if we could create a sort of colaborative wiki, we can have a Node.js core focused guide, and the community can add more specific guides for libraries and other stuff, what do you think @MarcinHoppe?

@nothingismagick
Copy link

Kind of late to the conversation, but I think missing here from #3 is the explicit mention of file-type detection - esp. considering the fact that e.g. node-mime only checks suffix not magic-numbers - and many devs consider a file suffix (instead of magic numbers) to be enough information to know what type of file they are dealing with. @lirantal knows exactly what I am referring to.

@MarcinHoppe
Copy link
Contributor Author

@nothingismagick Thanks, very good comment and not too late at all!

@nothingismagick
Copy link

nothingismagick commented Apr 15, 2019 via email

@lirantal
Copy link
Member

This thread is great and I want to keep the discussion going. @MarcinHoppe I like this issue and I see great value in putting more security-oriented guides on the Node.js website. I'd like to work on a doc like the Node.js API DOs an DONTs (https://foundation.nodejs.org/wp-content/uploads/sites/50/2018/06/NodeJS_FieldGuide_Building_APIs_Final.pdf)

@nothingismagick
Copy link

I had an experience this week that I found to be rather shocking - but also see it as an opportunity for node to shine.

In the course of a vuln triage, I discovered that the SPEC and security resources (made available by the W3C) for a specific issue I was investigating were not only painfully out of date, but also literally dangerous because of omissions.

I can't comment here in public about the specific issue yet, but the takeaway is that there are many underlying technologies that need better, more accessible security descriptions. Because of the ease with which complicated stacks can be thrown together, great deals of basic knowledge seem to be ignored - or worse - trapped in historical limbo and out of touch with the modern web.

@lirantal
Copy link
Member

If you could share that in a private forum on the security wg slack we could invite you. I'd be happy to learn more about this in terms of practical advice on what could be done better.

@nothingismagick
Copy link

Sure - I'd be glad to disclose there.

@fraxken
Copy link
Member

fraxken commented Jul 17, 2022

I think we are recently moving toward that goal. The idea is to use the work on the threat model as a foundation for a new user documentation (which will be security oriented).

I think however we still have no issue for this since if I remember we are waiting to finish the threat model. cc @UlisesGascon @RafaelGSS (correct me if I say something wrong 😊).

@lirantal
Copy link
Member

The threat model is definitely part of it, but I think @nothingismagick had also wanted general best practices for developer security, which I don't think we're going to encompass in the threat model we're building, as that's more around securely running Node.js applications, rather than secure coding conventions.

@RafaelGSS
Copy link
Member

Actually, we're going to create two documents:

  1. Threat Model (current in development)
  2. A tutorial document (we haven't defined a name yet) -- This is the best practices document that @nothingismagick was referring to.

So, we'll certainly address this issue at some moment.

@arhart
Copy link

arhart commented Aug 11, 2022

Per Node.js Security WorkGroup Meeting 2022-08-04 minutes the security guidance will be superseded by the Best Practices Document #819

@github-actions
Copy link
Contributor

This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

@GuanyuChen
Copy link

mark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests