Default and Advanced Setup

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 11 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Code Scanning Fundamentals: Default and Advanced Setup

Introduction: Why Code Scanning Matters

In the modern software development lifecycle, the speed at which we push code to production is often prioritized. However, speed without security is a recipe for technical debt and potential data breaches. Code scanning—often referred to as Static Application Security Testing (SAST)—is the practice of analyzing your source code to identify vulnerabilities, logic errors, and insecure coding patterns before the code is ever executed. By integrating these checks into your daily workflow, you transform security from a final "gatekeeper" step into an ongoing, automated process.

This lesson focuses on the transition from default, "out-of-the-box" security setups to advanced, customized configurations. Many developers assume that simply enabling a default scanner is sufficient. While defaults are an excellent starting point, they are often designed to be broad and non-intrusive, meaning they might miss specific vulnerabilities unique to your application's architecture or language stack. Understanding how to configure these tools allows you to tighten your security posture, reduce false positives, and ensure that your automated checks are actually relevant to the code you are writing.

As we move through this guide, we will explore the mechanics of how code scanning tools parse your repository, how to customize the rules engine to suit your specific project needs, and how to maintain these configurations as your codebase evolves. By the end of this lesson, you will be able to move beyond generic alerts and build a tailored security pipeline that acts as a true safeguard for your development team.


Not read yet

Understanding the Anatomy of a Code Scan

Before diving into configuration, it is important to understand what a code scanner actually does. When you initiate a scan, the engine performs a series of operations to interpret your code. It doesn't just read the text files; it builds an internal representation of your application.

The Scan Lifecycle

  1. Code Checkout: The scanning engine retrieves the source code from your version control system.
  2. Environment Preparation: The tool identifies the languages and frameworks used (e.g., detecting a package.json for Node.js or a pom.xml for Java).
  3. Compilation and Dependency Resolution: Many advanced scanners need to resolve dependencies to understand how different modules interact.
  4. Static Analysis: The engine traverses the Abstract Syntax Tree (AST) or Control Flow Graph (CFG) of your code to spot dangerous patterns.
  5. Reporting: The engine correlates findings against a database of known vulnerability patterns and generates a report.

Callout: Static vs. Dynamic Analysis It is common to confuse SAST (Static) with DAST (Dynamic) testing. Static analysis looks at the code while it is at rest—no execution happens. Dynamic analysis, conversely, involves interacting with the running application to find vulnerabilities that only appear during runtime, such as configuration issues or broken authentication flows. A mature security strategy requires both.


Not read yet

Default Setup: The "Quick Start" Approach

Most modern platforms provide a "default" mode for code scanning. This typically involves a single-click configuration that auto-detects your language and applies a standard set of security rules. This is usually managed through a configuration file in your repository, often located in a hidden directory like .github/workflows/ or similar.

Configuring the Default Workflow

When you enable the default setup, you are essentially telling the platform to run a set of industry-standard queries. These queries look for common issues like:

  • SQL Injection vulnerabilities.
  • Hardcoded secrets (API keys, passwords, tokens).
  • Path traversal issues.
  • Insecure cryptographic implementations.

The benefit of this approach is simplicity. You do not need to be a security expert to get started. You simply enable the feature, and the platform handles the infrastructure, the update cycles for the rule sets, and the integration into your pull request interface.

Tip: Start with Defaults If you are new to code scanning, always begin with the default configuration. Do not attempt to write custom rules until you have successfully managed the noise and false positives generated by the standard rule set. This allows you to calibrate your team's reaction to security alerts before adding more complexity.


Not read yet

Advanced Setup: Customizing for Your Stack

While default configurations cover the "low-hanging fruit," they often fail to account for the nuances of custom frameworks, internal libraries, or specific business logic vulnerabilities. Advanced setup involves tailoring the scanning engine to ignore irrelevant files, include specific custom rules, or adjust the sensitivity of the analysis.

Customizing the Configuration File

Most scanning tools use a YAML-based configuration file. Here is an example of a configuration snippet that moves beyond the default:

# .security-config.yml
name: "Advanced Code Scan"
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  analyze:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Initialize Scanner
        uses: security-tool/init@v2
        with:
          languages: 'javascript,python'
          queries: 'security-extended,security-and-quality'
          config-file: .github/codeql/custom-config.yml

In the example above, we move from a generic scan to a targeted one by specifying:

  1. Languages: Restricting the scan to only the languages relevant to the repository saves time and reduces false positives from irrelevant files.
  2. Query Suites: By adding security-extended, we tell the engine to look for more complex patterns that might be missed by the basic suite.
  3. Custom Config Path: We point the tool to a specific file where we define our own exclusion rules and custom query overrides.

Managing False Positives

One of the biggest hurdles in advanced setup is "alert fatigue." If a scanner produces 500 alerts and 450 of them are false positives, developers will eventually ignore the tool entirely. To mitigate this, you must learn to use "suppression" or "ignore" files.

Most tools allow you to specify files or directories to skip. For instance, if you have a legacy directory that is slated for deletion, you might want to exclude it from the scan to focus your efforts on the active codebase.

# .github/codeql/custom-config.yml
paths-ignore:
  - '**/legacy-code/**'
  - '**/tests/**'
  - '**/vendor/**'

query-filters:
  - exclude:
      id: js/hardcoded-secret
      path: '**/config/dev-settings.js'

Warning: Exclusion Risks Be extremely cautious when excluding directories or specific rules. While it is tempting to suppress alerts to clear your dashboard, you might be accidentally shielding a critical vulnerability. Always document why a specific rule was suppressed in the configuration file itself using comments.


Not read yet

Deep Dive: Building Custom Rules

Sometimes, a vulnerability is specific to your organization. For example, you might have a custom internal library that wraps database calls. If your developers use this library incorrectly, it could lead to SQL injection. Standard scanners don't know about your internal library, so they won't flag the misuse.

The Logic of a Custom Rule

To create a custom rule, you must define two things:

  1. The Source: Where the dangerous data enters the application (e.g., user input).
  2. The Sink: Where that data is used in a dangerous way (e.g., a database query).

Advanced tools allow you to write custom queries using a domain-specific language. You define the "flow" of data. If the data flows from the source to the sink without passing through your custom validation function, the scanner flags it as a vulnerability.

Steps to Implement a Custom Rule:

  1. Identify the Pattern: Document the specific code structure that is dangerous.
  2. Write the Prototype: Create a small, isolated test file that contains both a vulnerable example and a non-vulnerable example.
  3. Draft the Query: Use the tool's documentation to write a query that matches your pattern.
  4. Test the Query: Run the scanner against your prototype file. If it flags the vulnerable example and ignores the safe one, it is ready.
  5. Deploy: Add the custom query to your repository's configuration.

Not read yet

Industry Best Practices for Code Scanning

Successful implementation of code scanning is as much about culture as it is about technology. Even the most advanced configuration will fail if the development team does not trust the output.

1. Integrate into the Pull Request

The most effective place for a code scan is during the Pull Request (PR) process. By blocking a merge until security issues are addressed, you ensure that vulnerabilities never make it into the main branch.

2. Prioritize by Severity

Not all vulnerabilities are created equal. Focus your team's efforts on "Critical" and "High" severity issues first. If you attempt to fix every single "Low" or "Informational" warning, you will burn out your developers.

3. Automate the Remediation Guidance

The best scanners don't just report the issue; they provide a link to documentation on how to fix it. If your tool supports it, configure it to show these suggestions directly in the PR comments.

4. Regularly Review Your Configurations

Codebases change. A configuration that worked six months ago might be obsolete today. Schedule a quarterly review of your .security-config.yml and related files to ensure your exclusion lists are still valid and your rulesets are up to date.

5. Foster a "Security Champion" Culture

Appoint one developer on each team to be the "Security Champion." This person should be the go-to expert for understanding the scanner's output and helping other developers resolve complex findings.


Not read yet

Common Pitfalls and How to Avoid Them

Pitfall 1: The "Big Bang" Deployment

Many teams attempt to turn on code scanning for the entire organization overnight. This usually results in thousands of alerts, causing panic and frustration.

  • The Fix: Start with a pilot project. Enable scanning on one non-critical repository. Fine-tune the setup, clear the backlog, and then roll it out to other teams gradually.

Pitfall 2: Ignoring the "Noise"

When developers see hundreds of alerts, they tend to assume the tool is broken.

  • The Fix: Dedicate time to "tuning" the scanner. If a specific rule is flagging false positives, investigate why. Often, it's because the scanner doesn't understand your specific framework configuration. Adjust the ruleset rather than just ignoring the alerts.

Pitfall 3: Treating Security as a One-Time Event

Running a scan once is not enough. You need to ensure that the scanner runs on every commit.

  • The Fix: Use server-side webhooks or CI/CD pipeline triggers to ensure that every single code change is scanned automatically. Never rely on developers to remember to run the scan manually.

Not read yet

Comparison Table: Default vs. Advanced Configuration

Feature Default Setup Advanced Setup
Effort Low (Single click) High (Requires tuning)
Detection Scope Standard vulnerabilities Custom/Business logic flaws
False Positives Often high Low (After tuning)
Maintenance None (Auto-updated) Moderate (Requires oversight)
Best For Small projects/Prototypes Large, complex applications

Advanced Concepts: Integrating with Issue Tracking

A robust security program does not exist in isolation. If a code scanner finds a critical vulnerability, that information needs to be tracked. Many advanced setups involve pushing scan results directly into an issue tracking system like Jira or GitHub Issues.

Why Integrate?

  • Accountability: You can assign a specific developer to fix the vulnerability.
  • Visibility: Management can see the "security debt" of the project.
  • Workflow: You can track the lifecycle of a vulnerability from "Found" to "Fixed" to "Verified."

Example Workflow

  1. Scan Runs: The CI/CD pipeline detects a critical SQL injection.
  2. Issue Created: The scanner automatically opens an issue in your tracking system, including the file path and line number.
  3. Developer Fixes: The developer writes a fix and references the issue number in their commit message.
  4. Auto-Close: Once the code is merged and a new scan runs, the scanner detects that the vulnerability is gone and automatically closes the issue.

This level of automation removes the manual overhead of managing security tickets and ensures that your security metrics are always accurate.


Not read yet

Handling Dependency Scanning (SCA)

While this lesson focuses on code scanning (SAST), it is impossible to ignore Software Composition Analysis (SCA). Your code relies on third-party libraries, and those libraries often contain vulnerabilities.

Why SAST isn't enough

Code scanning looks at your code. If you are using a library (e.g., a logging library or a web framework) that has a known vulnerability, SAST might not catch it because the code itself looks "correct." You need an SCA tool to scan your package.json, requirements.txt, or pom.xml files to identify vulnerable versions of dependencies.

Best Practice

Combine your SAST and SCA workflows. In your CI/CD configuration, run both scanners in parallel.

  • SAST: Checks for logic bugs and bad coding patterns.
  • SCA: Checks for outdated, vulnerable dependencies.

By running both, you cover both the "homegrown" and "imported" risks in your application.


Not read yet

FAQ: Common Questions

Q: How often should I run code scans? A: Every time code is pushed. If you only run them weekly or monthly, you allow vulnerabilities to accumulate, making them much harder and more expensive to fix later.

Q: What if my team disagrees with a security finding? A: This happens. If you disagree with a finding, document the reason in your configuration file. If it’s a genuine false positive, the tool vendor usually has a way to report it so they can improve their engine. If it’s a design choice, ensure you have documented the compensatory controls you have in place to mitigate the risk.

Q: Does code scanning slow down my build time? A: It can. If you have a massive codebase, a full scan can take a long time. To mitigate this, look for tools that support "incremental scanning," which only scans the files that have changed in the current commit rather than the entire repository.

Q: Should I use multiple scanners for the same language? A: Sometimes, yes. Different scanners have different strengths. One might be excellent at finding SQL injection, while another might be better at finding configuration errors. However, keep in mind that this increases the amount of noise and management overhead. Start with one, and only add a second if you find a specific gap in coverage.


Not read yet

Key Takeaways

  1. Start Simple: Always begin with default configurations to establish a baseline. Do not rush into complex custom rules until you are comfortable managing the standard output.
  2. Prioritize Context: Use exclusion files wisely. Removing noise is essential for developer adoption, but ensure you are not accidentally suppressing critical security alerts.
  3. Automate Everything: Security should be a non-negotiable part of your CI/CD pipeline. If it isn't automated, it isn't being done consistently.
  4. Focus on Data Flow: When writing custom rules, always think about the "Source" (where the data comes from) and the "Sink" (where it is used). This is the foundation of effective static analysis.
  5. Build a Security Culture: Tools are only as good as the people using them. Empower your team to understand why a finding is a risk, rather than just telling them to fix it.
  6. Don't Ignore Dependencies: Code scanning is only half the battle. Complement your SAST workflow with Software Composition Analysis (SCA) to catch vulnerabilities in third-party libraries.
  7. Iterate and Improve: Security is a journey, not a destination. Regularly review your scan results and configuration files to adapt to new threats and the evolving nature of your codebase.

By following these fundamental principles, you can transition from a reactive security posture to a proactive one. Remember, the goal of code scanning is not to achieve a "zero-alert" state, but to provide your team with the visibility they need to write safer code. Every alert you address is a potential incident you have prevented, making your application more resilient and your users more secure.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.