Securing Your Code with AWS Inspector: A Comprehensive Guide to Code Security Scanning



This content originally appeared on DEV Community and was authored by Venkata Pavan Vishnu Rachapudi

AWS Inspector Code Security automatically scans your code for vulnerabilities so you don’t have to. Here’s how to set it up and catch security issues before they hit production.

What is AWS Inspector Code Security?

AWS Inspector Code Security is a fully managed service that scans your:

  • Source code for security vulnerabilities (SAST) – supports Python, Java, JavaScript .etc.
  • Dependencies for known CVEs (SCA) – scans npm, pip, Maven, etc.
  • Infrastructure scripts for misconfigurations (IaC) – Terraform, CloudFormation, CDK.

  • For More on Supported Sources

Why You Need This

Your code probably has vulnerabilities you don’t know about:

  • XSS from unescaped user input (CWE-79)
  • Command injection from shell execution (CWE-78)
  • Hardcoded secrets and API keys (CWE-798)
  • Misconfigured S3 buckets and databases
  • Vulnerable dependencies with known CVEs
  • LDAP/SQL injection vulnerabilities (CWE-89, CWE-90)

Manual code reviews miss these. AWS Inspector uses advanced semantic analysis and data flow tracking to catch them automatically, with findings mapped to CWE (Common Weakness Enumeration) classifications.

Quick Setup (5 minutes)

1. Create Configuration


# Navigate to AWS Console > Inspector > Code Security
# Click "Create Configuration"
# Enable: SAST ✓ Secrets ✓ SCA ✓
# Set frequency: Weekly

2. Connect Your Repo

Works with GitHub, GitLab:

# Click "Connect to GitHub"
# Authorize AWS Inspector app
# Select repositories to scan
# Done!

3. Authorization

Inspector needs permission to:

  • Read your repository contents
  • Set up webhooks for automatic scanning
  • Access commit history

Hands-On Demonstration: Vulnerable Application

To showcase AWS Inspector’s capabilities, I’ve created a demonstration repository containing intentionally vulnerable code. Let’s explore the vulnerabilities and how Inspector detects them.

Application Vulnerabilities

1. Cross-Site Scripting (XSS)

@app.route('/search')
def search():
    query = request.args.get('q', '')
    # Vulnerable: Unescaped user input
    template = f"<h1>Search Results for: {query}</h1>"
    return render_template_string(template)

This code directly injects user input into HTML without sanitization, allowing attackers to execute malicious scripts.

Test payload: <script>alert('XSS')</script>

2. Command Injection

@app.route('/ping')
def ping():
    host = request.args.get('host', 'localhost')
    # Vulnerable: Direct command execution
    result = subprocess.run(f"ping -n 1 {host}", shell=True, capture_output=True, text=True)
    return f"<pre>{result.stdout}</pre>"

This vulnerability allows attackers to execute arbitrary system commands by manipulating the host parameter.

Test payload: localhost; whoami

3. LDAP Injection

@app.route('/ldap')
def ldap_search():
    username = request.args.get('username', '')
    # Vulnerable: Direct string concatenation in LDAP filter
    ldap_filter = f"(&(objectClass=user)(sAMAccountName={username}))"

Unsanitized LDAP filter construction allows attackers to manipulate directory queries.

Test payload: admin)(&(objectClass=*

Infrastructure Vulnerabilities

The Terraform configuration includes several security misconfigurations:

# Vulnerable: Public S3 bucket
resource "aws_s3_bucket_public_access_block" "vulnerable_bucket_pab" {
  bucket = aws_s3_bucket.vulnerable_bucket.id

  block_public_acls       = false
  block_public_policy     = false
  ignore_public_acls      = false
  restrict_public_buckets = false
}

This configuration creates a publicly accessible S3 bucket, violating security best practices.

AWS Inspector in Action

Repository Overview

Once configured, AWS Inspector provides a comprehensive dashboard showing:

  • Project Status: Current scanning status and last scan timestamp
  • Integration Details: Connected SCM platform and repository information
  • Scan Configuration: Applied scanning rules and frequency
  • Findings Summary: Overview of detected vulnerabilities
  • Export Findings : We can export findings to S3 Bucket which should be Private
  • Suppression Rules : to Suppress vulnerabilities like low ,etc and even related code level, source code type etc

Finding Severity Levels

AWS Inspector classifies findings into five severity levels:

  • Critical: Immediate attention required, high risk of exploitation
  • High: Significant security risk, address promptly
  • Medium: Moderate risk, include in regular development cycle
  • Low: Minor issues, address during maintenance
  • Informational: Best practice recommendations

Assessment Types

  • On-demand scans: Manual scans when you need them
  • Scheduled scans: Automated weekly/daily scanning
  • Event-driven scans: Triggered by commits or pull requests

Conclusion

AWS Inspector Code Security represents a significant advancement in automated security scanning, providing comprehensive coverage for modern application development. By integrating security scanning directly into the development workflow, organizations can identify and remediate vulnerabilities before they reach production environments.

Resources

Ready to secure your code? Try the Demo Repository – Hands-on vulnerable code example swith intentionally vulnerable examples to see AWS Inspector in action. Remember: never deploy vulnerable demo code to production!


This content originally appeared on DEV Community and was authored by Venkata Pavan Vishnu Rachapudi