Vulnerability Scanner
Overview
The Vulnerability Scanner extension for Visual Studio Code helps developers identify security vulnerabilities in JavaScript code. It automatically scans for common security risks, such as the use of unsafe functions, insecure practices, and potential injection attacks, to improve the security of your codebase.
Features
- Comprehensive Code Scanning: Scans your JavaScript codebase for vulnerabilities such as the use of
eval()
, innerHTML
, localStorage
, and other potentially insecure functions or patterns.
- Security Alerts: Displays warnings, errors, and suggestions to address potential vulnerabilities.
- Customizable Security Rules: Extend the built-in rules with your own to tailor the scan to your project’s security requirements.
- Detailed Diagnostic Information: Highlights specific lines of code where security issues are detected, with explanations and recommended actions.
Installation
Via VS Code Marketplace
- Open VS Code Marketplace.
- Search for Vulnerability Scanner.
- Click Install.
Manual Installation
- Download the
.vsix
file: Download here.
- Open VS Code.
- Go to the Extensions view by clicking the Extensions icon in the Activity Bar or pressing
Ctrl+Shift+X
.
- Click the three-dot menu icon in the top right corner and select Install from VSIX....
- Select the
.vsix
file you downloaded.
Usage
Scanning Code
- Open the Command Palette (
Ctrl+Shift+P
).
- Type and select Scan Code for Vulnerabilities.
- The extension will analyze the currently open file or the selected code block, highlighting any vulnerabilities in the Problems panel.
Example Warnings
Here are a few examples of vulnerabilities detected by the extension:
Unsafe usage of eval()
:
eval("console.log('Dangerous code')"); // Warning: avoid using eval().
Usage of innerHTML
:
document.getElementById("content").innerHTML = "<p>Content</p>"; // Warning: avoid using innerHTML due to XSS risk.
Potential SQL Injection:
const query = `SELECT * FROM users WHERE name = '${userInput}'`; // Error: possible SQL injection.
Customizing Rules
You can customize the set of rules by editing your workspace's settings.json
file:
{
"vulnerabilityScanner.rules": ["no-eval", "no-innerHTML", "no-sql-injection"]
}
no-eval
: Detects the use of eval()
.
no-innerHTML
: Flags the usage of innerHTML
for potential XSS attacks.
no-sql-injection
: Warns about unsanitized SQL queries prone to injection.
Supported Vulnerability Rules
Here are some of the built-in rules:
- Avoid using
eval()
: Flags usage of eval()
.
- Avoid
innerHTML
: Detects potential XSS risks with innerHTML
.
- SQL Injection: Detects unsanitized SQL queries.
- Insecure Hashing Algorithms: Flags the usage of weak hashing algorithms (e.g., MD5, SHA-1).
- Hardcoded Secrets: Detects hardcoded API keys and passwords in the code.
- Insecure Random Numbers: Warns about the use of
Math.random()
in cryptographic contexts.
- Potential Command Injection: Detects unsanitized
exec()
function calls.
- Weak JWT Secret: Warns about using short JWT secrets.
Contributing
We welcome contributions from the community! To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
).
- Commit your changes (
git commit -am 'Add new feature'
).
- Push to the branch (
git push origin feature/your-feature
).
- Create a new Pull Request.
Issues
If you encounter any issues, have questions, or want to request a feature, please file an issue on the Issues page.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgements
This README update enhances your extension's description with specific examples, supported rules, and contribution guidelines.