ESLint Security Scanning
Introduction: From Theory to Practice with ESLint
Welcome to the first practical lesson of the course! In the previous lesson, we learned that SAST (Static Application Security Testing) tools scan code "at rest" to find security flaws early in the development process. Now, we will move from theory to practice by configuring and using our first tool: ESLint. While many developers know ESLint as a tool for finding syntax errors or enforcing coding style, it becomes a powerful security scanner when we add the right plugins.
In this lesson, we will work with a "Pastebin-style" application written in TypeScript. We will configure ESLint to automatically detect dangerous coding patterns, specifically focusing on Object Injection and Regular Expression Denial of Service (ReDoS). You will learn how to set up the configuration file, run the scanner, interpret the warnings the tool generates, and, most importantly, rewrite the vulnerable code to make it secure.
Setting Up ESLint with the Security Plugin
To turn ESLint into a security tool, we need to tell it specifically what to look for. By default, ESLint only checks for standard JavaScript and TypeScript errors. We extend its capabilities by using a configuration file, typically named .eslintrc.cjs in modern JavaScript projects. This file acts as the instruction manual for the scanner, telling it which files to read and which rules to enforce.
In the CodeSignal environment, the necessary libraries are already installed for you. However, understanding the configuration is critical so you can replicate this setup in your own projects. We need to configure the parser to understand TypeScript syntax and load the security plugin.
Here is the basic structure of our configuration file:
The parser setting is essential because standard ESLint cannot read TypeScript's type definitions. The plugins array is where we activate eslint-plugin-security.
Both eslint-plugin-security and @typescript-eslint provide convenient recommended configurations that bundle their best-practice rules together and can be enabled with a single line in the extends array. Notably, the @typescript-eslint recommended config also disables core ESLint rules known to conflict with TypeScript parsing, saving you from subtle false positives. In a real project, you would typically extend both:
For this lesson, we will define our rules explicitly rather than using the recommended shorthand. This makes it clear exactly which rules are active and why, which is important for learning purposes.
