JavaScript Security Pitfalls
Tags: javascript, security, node
Published: 2020-07-01 09:51:47

---
canonical_url: https://marcinhoppe.com/javascript-security-pitfalls
---

# Why bother with JavaScript security?

The Web runs on JavaScript. If you are a software developer, chances are you are writing JavaScript. Even if you are not, you rely on tools and applications written in this popular language. You would not be reading this article without JavaScript.

A lot has been written about [Web security](https://owasp.org/www-project-top-ten/). Many software engineers know what [SQL injection](https://owasp.org/www-project-top-ten/OWASP_Top_Ten_2017/Top_10-2017_A1-Injection) is and can tell [cross-site scripting](https://owasp.org/www-project-top-ten/OWASP_Top_Ten_2017/Top_10-2017_A7-Cross-Site_Scripting_(XSS)) (XSS) from [cross-site request forgery](https://owasp.org/www-community/attacks/csrf) (CSRF). And yet, security issues that are unique to JavaScript remain unknown to many developers.

Unfortunately, this does not mean that those vulnerabilities cannot be exploited by attackers seeking fame, fortune, or revenge. They certainly can.

# A series is born

The goal of this blog post series is to help you become a better JavaScript developer. I will help you to build a strong mental model of the most prevalent vulnerabilities that plague JavaScript code. Follow along to learn how to write secure and robust code that prevents them.

## Here be dragons

JavaScript is a bit of an odd animal in the programming language menagerie. Rapid development and massive popularity gave us language features and coding patterns that may easily lead to exploitable security bugs.

- **Dynamic typing**. JavaScript variables can refer to objects of different types. A variable can refer to a number, a string, or an object, depending on the flow of control. When you look at the code, you do not always know the types of your variables. It may lead to unintentional information disclosure or other security issues.

- **Dynamic code execution**. JavaScript programs can invoke the JavaScript engine at runtime. It sounds like a really powerful feature, and it is. Also, this is what attackers dream about: the ability to inject their code into your application.

- **Prototype pollution**. JavaScript has a pretty unusual inheritance mechanism. Instead of expressing static relationships between classes, the same goal is achieved by building dynamic relationships between objects. If attackers can modify the objects forming the prototype chain, they may alter the behavior of your code in unforeseen ways.

This series of posts will look into those problems in detail. It will also offer actionable guidance on how to find and avoid them.

# What’s next?

The next post in this series will explain the JavaScript security model in two most popular runtime environments: Web browsers and Node.js.

# Video course

I am also working on a video course JavaScript Security: Best Practices on [Pluralsight](https://www.pluralsight.com/). It will be a part of the [JavaScript Core Language](https://www.pluralsight.com/paths/javascript-core-language) learning path. Learn more on the [Courses](https://marcinhoppe.com/courses/) page on my website and subscribe to the newsletter to get regular updates about the progress.