<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged sonarqube</title>
<link>https://coderlegion.com/tag/sonarqube</link>
<description>Powered by Question2Answer</description>
<item>
<title>Sonar Duplication in TypeScript Static Sites</title>
<link>https://coderlegion.com/30558/sonar-duplication-in-typescript-static-sites</link>
<description>&lt;p&gt;When a static site grows to include extensive configuration registries, locale catalogs, and curated content records, code analysis tools often flag repeated structures or raw data. Developers frequently wonder how SonarQube handles overall duplication when large amounts of data live in TypeScript files versus dedicated data structures. The core question is whether moving repeated records out of source code and into JSON changes the analyzer metrics or merely hides repetitive data from the report. SonarQube evaluates code duplication strictly within the files included in its analysis scope. When a project stores large registries in TypeScript, those files are scanned, and any structural repetition is measured. If those same records are converted to JSON and excluded by the Sonar configuration, the duplication metrics drop to zero for those payloads simply because they are no longer part of the analyzed source code. This leaves developers with a methodological distinction to keep in mind. A zero percent duplication score on the main branch means that the analyzed TypeScript and JavaScript code contains no measured duplication, but it does not mean the entire repository is free of repeated text or data values. Understanding this boundary prevents confusion when comparing local file contents against authenticated CI scan results. For a related implementation, see &lt;a rel=&quot;nofollow&quot; href=&quot;https://raylabs.app/articles/android-static-analysis-lint-detekt-ci/&quot;&gt;Static Analysis Lint Detekt Ci&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To manage this architecture safely, developers must separate analyzer scope from data storage trade-offs. Storing large registries in TypeScript offers inline type checking and immediate autocompletion, but it increases the lines of code processed by quality gates and can artificially inflate duplication numbers if similar structures repeat across components. Moving registries into JSON files keeps the source code clean and removes raw data from the analyzer scope, but it requires an explicit validation layer to maintain type safety. Without strict schema checks, runtime errors can slip past the compiler when data files drift from their expected shapes. The correct approach relies on typed imports from JSON modules, backed by automated regression tests and exact data parity checks during the build pipeline. This design preserves the developer experience of type-safe APIs while keeping the SonarQube scanner focused purely on executable logic and helper functions. For a related implementation, see &lt;a rel=&quot;nofollow&quot; href=&quot;https://raylabs.app/articles/reclaim-macos-developer-storage-safely/&quot;&gt;Reclaim Macos Developer Storage Safely&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Consider an architectural example from a data-heavy static site using Astro and TypeScript. In the initial implementation, timer durations, audio envelope configurations, and category tags lived inside a shared TypeScript constants file. While convenient, this approach exposed raw data arrays directly to the linter and the code duplication scanner. Refactoring this setup involves moving the raw payloads into structured JSON files and importing them with strict type assertions. The following configuration illustrates how TypeScript consumes the externalized registry while retaining strict validation.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &quot;timerDefaultDuration&quot;: 300,
  &quot;allowedCategories&quot;: [
    &quot;focus&quot;,
    &quot;short-break&quot;,
    &quot;long-break&quot;
  ],
  &quot;audioEnvelope&quot;: {
    &quot;attack&quot;: 0.05,
    &quot;release&quot;: 0.1
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To ensure this external data satisfies the application requirements without relying on SonarQube to catch data repetition, the build pipeline runs a series of parity and regression checks. The following TypeScript snippet demonstrates how a validation utility confirms the imported JSON matches the expected runtime interface before the site compiles.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-typescript&quot;&gt;import registryData from './timer-registry.json';

interface TimerRegistry {
  timerDefaultDuration: number;
  allowedCategories: string[];
  audioEnvelope: {
    attack: number;
    release: number;
  };
}

function validateRegistry(data: unknown): asserts data is TimerRegistry {
  if (typeof data !== 'object' || data === null) {
    throw new Error('Invalid registry format');
  }
  const reg = data as Record&amp;lt;string, unknown&amp;gt;;
  if (typeof reg.timerDefaultDuration !== 'number') {
    throw new Error('Missing or invalid timerDefaultDuration');
  }
  if (!Array.isArray(reg.allowedCategories)) {
    throw new Error('Missing or invalid allowedCategories');
  }
}

validateRegistry(registryData);
export const registry: TimerRegistry = registryData;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Evaluating the success of this remediation requires examining both quality gate outcomes and test suite coverage. After moving static registries to JSON and consolidating repeated timer helpers, authenticated scans on the main branch confirm a clean analysis state. The analyzed code metrics record zero duplicated blocks and zero duplicated lines across more than nine thousand lines of source code. Furthermore, New Code duplication remains safely below the configured threshold, and the overall Quality Gate status resolves as passed. Local test suites execute successfully across all unit, integration, and end-to-end browser tests, proving that externalizing data arrays does not disrupt runtime behavior. Developers examining these reports must remember that local clone tools and pull request gates primarily act as proxies or New Code checks, whereas definitive overall metrics require an authenticated analysis run on the main branch. Maintaining clear distinctions between code duplication metrics and data registry structures ensures that quality gates accurately reflect the health of the application logic.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/30558/sonar-duplication-in-typescript-static-sites</guid>
<pubDate>Sat, 10 Oct 2026 06:02:04 +0000</pubDate>
</item>
<item>
<title>Fixing SonarCloud Quality Gate Rating E to A in Production</title>
<link>https://coderlegion.com/30151/fixing-sonarcloud-quality-gate-rating-e-to-a-in-production</link>
<description>&lt;h3 id=&quot;technical-context-and-real-problem&quot;&gt;Technical Context and Real Problem&lt;/h3&gt;
&lt;p&gt;Integrating automated static code analysis into a production web application often surfaces unexpected technical debt. In RayLabs Site, introducing SonarCloud static analysis immediately blocked the deployment pipeline with a failed Quality Gate. The project faced a Security Rating E driven by Blocker DOM XSS findings, unpinned CDN scripts, and cryptographically weak pseudo-random number generator usage. It also faced a Reliability Rating C driven by unhandled floating promises, sorting arrays without explicit locale comparators, and duplicate CSS declarations.&lt;/p&gt;
&lt;p&gt;Because the SonarCloud project was private, local unauthorized tools and curl commands returned generic Not Found responses, making issue discovery impossible without guesswork. Blindly guessing which lines triggered specific Sonar rules or attempting to reverse engineer closed AST engines wastes valuable engineering hours. A systematic, data-driven approach is required to turn static analysis failures into a clean build.&lt;/p&gt;
&lt;h3 id=&quot;in-pipeline-tokenized-diagnostic-triage&quot;&gt;In-Pipeline Tokenized Diagnostic Triage&lt;/h3&gt;
&lt;p&gt;Instead of guessing, the first step is adding a diagnostic triage step directly to the continuous integration workflow running after the main scanner. Authenticated via repository secrets, this step automatically calls the SonarCloud Web API with pagination, outputting the exact rule ID, file path, line number, severity, and remediation advice into the runner log. This turns a blind fix into a deterministic checklist.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yaml&quot;&gt;- name: Fetch SonarCloud Issues Diagnostic
  env:
    SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  run: |
    curl -s -u &quot;$SONAR_TOKEN:&quot; &quot;https://sonarcloud.io/api/issues/search?componentKeys=ufebri_raylabs-site&amp;amp;resolved=false&quot; \
    | jq '.issues[] | {rule: .rule, component: .component, line: .line, message: .message}'
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;web-crypto-api-migration-over-math-random&quot;&gt;Web Crypto API Migration Over Math Random&lt;/h3&gt;
&lt;p&gt;Sonar flags standard pseudo-random number generators whenever used in security-sensitive contexts like session codes or token generation. Rather than installing heavy external dependencies, applications can implement a lightweight, zero-dependency helper using native browser APIs.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;function secureRandom() {
  if (typeof window !== 'undefined' &amp;amp;&amp;amp; window.crypto?.getRandomValues) {
    const buf = new Uint32Array(1);
    window.crypto.getRandomValues(buf);
    return buf[0] / 0x100000000;
  }
  return 0.5;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Applying this helper universally across audio synthesis, room codes, and particle animations completely clears the relevant security rules without incurring runtime overhead.&lt;/p&gt;
&lt;h3 id=&quot;breaking-taint-flows-and-managing-dependencies&quot;&gt;Breaking Taint Flows and Managing Dependencies&lt;/h3&gt;
&lt;p&gt;Sonar security taint analyzers trace localStorage reads directly into dynamic DOM sinks. Custom boolean helper functions defined in another scope often fail to break the taint flow because static analyzers cannot always guarantee that the string was modified. Combining inlined schema checks with standard recognized sanitizers like encodeURI mathematically breaks the taint flow while ensuring valid raster images render correctly.&lt;/p&gt;
&lt;p&gt;For dynamic external scripts, static analysis flags code lacking integrity checks. Pinning unversioned content delivery network URLs to exact immutable releases and computing cryptographic hashes enforces strict anonymous cross-origin policies, preventing supply chain vulnerabilities. For a related implementation, see &lt;a rel=&quot;nofollow&quot; href=&quot;https://raylabs.app/articles/preventing-cloudflare-browser-integrity-check-from-blocking/&quot;&gt;Preventing Cloudflare Browser Integrity Check Blocking&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Achieving a zero-defect static analysis rating requires moving away from trial and error. By leveraging continuous integration secrets for diagnostic discovery, standardizing on native browser cryptographic primitives, utilizing explicit sort comparators, and guarding floating promises, engineering teams can clear quality gates reliably while maintaining high velocity.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/30151/fixing-sonarcloud-quality-gate-rating-e-to-a-in-production</guid>
<pubDate>Wed, 07 Oct 2026 15:02:22 +0000</pubDate>
</item>
<item>
<title>Catch vulnerabilities before they ship: local SonarQube setup (Part 2)</title>
<link>https://coderlegion.com/9955/catch-vulnerabilities-before-they-ship-local-sonarqube-setup-part-2</link>
<description>&lt;p&gt; &lt;/p&gt;
&lt;h3 id=&quot;introduction&quot;&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Static Application Security Testing (&lt;strong&gt;SAST&lt;/strong&gt;) is a crucial practice within the Software Security Development Life Cycle (&lt;strong&gt;SSDLC&lt;/strong&gt;) that enables developers to identify security vulnerabilities early in the code development phase. While understanding the concepts of &lt;strong&gt;SAST&lt;/strong&gt; is important, implementing it effectively in real-world projects is what ensures robust and secure software delivery.&lt;/p&gt;
&lt;p&gt;In this second part of our &lt;strong&gt;SAST&lt;/strong&gt; series, we focus on integrating the  &lt;strong&gt;SonarQube Cloud&lt;/strong&gt;, a popular static analysis tool, into the IntelliJ IDEA and running it using Docker. &lt;/p&gt;
&lt;p&gt;We will explore:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SonarQube Cloud for SAST&lt;/li&gt;
&lt;li&gt;Local scanning with SonarQube Cloud via IntelliJ IDEA&lt;/li&gt;
&lt;li&gt;Local scanning using Docker Compose with SonarQube image&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Tools:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SonarQube Cloud&lt;/li&gt;
&lt;li&gt;Spring Boot&lt;/li&gt;
&lt;li&gt;IntelliJ IDEA&lt;/li&gt;
&lt;li&gt;Docker-Compose&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Prerequisites:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a Spring Boot project using IntelliJ IDEA or the Spring Boot Initializr at &lt;a rel=&quot;nofollow&quot; href=&quot;https://start.spring.io&quot;&gt;https://start.spring.io&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Next&lt;/strong&gt; and generate the project without dependencies.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c07bbpqat146eju2p876.png&quot; alt=&quot;New Spring Boot project in IntelliJ EDIA&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3 id=&quot;sonarqube-cloud-for-sast&quot;&gt;SonarQube Cloud for SAST&lt;/h3&gt;
&lt;p&gt;SonarQube Cloud offers a hassle-free way to start static code analysis without managing your own infrastructure. It provides cloud-hosted scanning capabilities that analyze code quality, security vulnerabilities, bugs, and code smells.&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h4 id=&quot;setting-up-sonarqube-cloud&quot;&gt;Setting Up SonarQube Cloud&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Create an account:&lt;/strong&gt; Visit SonarQube’s official website and sign up for a free or paid cloud account.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Create a new project:&lt;/strong&gt; Once logged in, create a new project by providing your repository details.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Generate an authentication token:&lt;/strong&gt; For integrating scanning tools, generate a security token from your account settings. We must store it in a secret place, like in the GitHub Actions environment or repository secret.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configure project settings:&lt;/strong&gt; We need to set Quality Gates, SLAs, and rules according to our security policy. For a free account, we cannot create the Quality Gates; we must use the default one.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;SonarQube Cloud then becomes the central place to view detailed security reports and code quality metrics.&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h4 id=&quot;overview-of-sonarqube-s-cloud-capabilities-for-static-code-analysis&quot;&gt;Overview of SonarQube’s cloud capabilities for static code analysis&lt;/h4&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;SonarCloud is a fully managed SaaS platform for continuous static code analysis, designed to detect code quality issues, security vulnerabilities, and maintainability risks across modern software projects. It provides code coverage plugin integration that is used by 30+ different programming languages, including Java, Python, C#, JavaScript, TypeScript, and Go.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Capabilities&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cloud-hosted and fully managed:&lt;/strong&gt; SonarCloud removes the need for installation, hosting, or maintenance. This allows teams to focus solely on development and CI/CD pipelines. Use the cloud version if your company does not work under compliance regulations.&lt;/p&gt;
&lt;p&gt;SonarSource manages:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;uptime&lt;/li&gt;
&lt;li&gt;scaling&lt;/li&gt;
&lt;li&gt;rule updates&lt;/li&gt;
&lt;li&gt;language analyzers&lt;/li&gt;
&lt;li&gt;security patches&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deep Static Code Analysis:&lt;/strong&gt; SonarCloud performs comprehensive static analysis across many dimensions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Bug Detection. Identifies code paths that can lead to crashes, incorrect logic, or unintended behavior.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Security vulnerability detection. Finds CWE-based, OWASP-aligned issues such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SQL Injection&lt;/li&gt;
&lt;li&gt;Path traversal&lt;/li&gt;
&lt;li&gt;Input validation issues&lt;/li&gt;
&lt;li&gt;Hardcoded secrets&lt;/li&gt;
&lt;li&gt;Command injection&lt;/li&gt;
&lt;li&gt;Code Smells. Flags maintainability issues, duplicated code, bad design, and anti-patterns.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cognitive Complexity. Measures how difficult code is to understand and maintain.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multi-language support. Supports 30+ languages, including Java, Python, JavaScript, TypeScript, Go, C#, Kotlin, PHP, Terraform, YAML, and more.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Seamless CI/CD integration&lt;/strong&gt;: SonarCloud integrates natively with:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;CI providers:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GitHub Actions&lt;/li&gt;
&lt;li&gt;Azure Pipelines&lt;/li&gt;
&lt;li&gt;Bitbucket Pipelines&lt;/li&gt;
&lt;li&gt;GitLab CI&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Build tools: SonarQube provides integrations with build tools. For example, in our case, the Gradle Sonar plugin is used to run Sonar Scanner in the CI/CD pipeline.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pull request and branch analysis:&lt;/strong&gt; SonarCloud performs inline analysis during PR reviews, preventing issues from reaching the main branch. The free plan does not support this.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Quality Gates:&lt;/strong&gt; A Quality Gate defines the rules that code must satisfy before being merged. If a PR &lt;span class=&quot;text-red-400 font-bold&quot;&gt;fails&lt;/span&gt; the Quality Gate, the CI pipeline can block the merge. Adding custom Quality Gates is not supported by the free plan.&lt;/p&gt;
&lt;p&gt; Default checks include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;No new critical or blocker issues.&lt;/li&gt;
&lt;li&gt;Code coverage must meet a minimum threshold.&lt;/li&gt;
&lt;li&gt;No new bugs or security vulnerabilities.&lt;/li&gt;
&lt;li&gt;No new code duplications.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Test coverage and code metrics:&lt;/strong&gt; SonarCloud provides overall coverage and new code coverage, for example, for a specific PR or branch.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Organization and project dashboards:&lt;/strong&gt; SonarCloud provides rich dashboards for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Centralized issue tracking.&lt;/li&gt;
&lt;li&gt;Historical trend charts for issues, code coverage, and duplications.&lt;/li&gt;
&lt;li&gt;Hotspot security review.&lt;/li&gt;
&lt;li&gt;Code coverage progress.&lt;/li&gt;
&lt;li&gt;History of activities for each branch or PR.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Notifications and integrations:&lt;/strong&gt; Supports notifications via:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GitHub checks.&lt;/li&gt;
&lt;li&gt;GitLab merge requests.&lt;/li&gt;
&lt;li&gt;Slack.&lt;/li&gt;
&lt;li&gt;Email.&lt;/li&gt;
&lt;li&gt;Webhooks.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Open APIs and extensions:&lt;/strong&gt; SonarQube provides APIs to build custom dashboards and export metrics.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3 id=&quot;local-scanning-with-sonarqube-cloud-via-intellij-idea&quot;&gt;Local scanning with SonarQube Cloud via IntelliJ IDEA&lt;/h3&gt;
&lt;p&gt;Running local scans during development helps catch issues early before code is committed.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;h4 id=&quot;installing-and-configuring-the-sonarqube-plugin-in-intellij-idea&quot;&gt;Installing and configuring the SonarQube plugin in IntelliJ IDEA&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;Open IntelliJ IDEA.&lt;/li&gt;
&lt;li&gt;Navigate to &lt;strong&gt;File &amp;gt; Settings &amp;gt; Plugins&lt;/strong&gt; and search for the &quot;SonarQube&quot; plugin.&lt;/li&gt;
&lt;li&gt;Install and restart the &lt;strong&gt;IDE&lt;/strong&gt;. It must appear in the &lt;strong&gt;“Installed”&lt;/strong&gt; section.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s4jajteiwt0oi4e45myq.png&quot; alt=&quot;SonarQube plugin isntallation in IntelliJ&quot;&gt;&lt;/p&gt;
&lt;p&gt;  &lt;br&gt;
  &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Generate the authentication Sonar token.&lt;br&gt;
Go to the SonarCloud website, then My Account &amp;gt; Security &amp;gt; Generate Token, or click on this link &lt;a rel=&quot;nofollow&quot; href=&quot;https://sonarcloud.io/account/security&quot;&gt;https://sonarcloud.io/account/security&lt;/a&gt;, and you will be redirected to the token generation page. Enter the name of the token, typically where you want to use it, and click the “Generate Token” button.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vn7kh7osyq8ym6piv0bi.png&quot; alt=&quot;SonarQube cloud security tab&quot;&gt;&lt;/p&gt;
&lt;p&gt;  &lt;br&gt;
  &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Configure the plugin by adding your SonarQube Cloud server URL and authentication token.&lt;br&gt;
Click on the SonarQube plugin icon, then select the gear icon, as shown in the screenshot.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lu9tiko4omcb2h2znuq6.png&quot; alt=&quot;IntelliJ SonarQube plugin icon&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;Enter the Project key of your SonarQube project and click “Configure the connection”.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uasp34yysvftud0nzobz.png&quot; alt=&quot;IntelliJ SonarQube plugin configuration 1&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;You will see the Connection section, click the plus to add a new connection.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oie6px14di0ukwgt0iky.png&quot; alt=&quot;IntelliJ SonarQube plugin configuration 2&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;Enter the name of the connection and click “Next”.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mo5pf3m6y7lm5tlbpfb8.png&quot; alt=&quot;IntelliJ SonarQube plugin configuration 3&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;Paste the generated token, or you can even create the token from this IDE window. Click “Next”, and the IDE will attempt to connect to &lt;strong&gt;Sonar Cloud&lt;/strong&gt;. You will see that authentication is &lt;span class=&quot;text-green-400 font-bold&quot;&gt;successful&lt;/span&gt; if the connection is established.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bkoqzfpdoy1c6i3n3acb.png&quot; alt=&quot;IntelliJ SonarQube plugin configuration 4&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h4 id=&quot;running-local-scans&quot;&gt;Running local scans&lt;/h4&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;After configuration, you can run &lt;strong&gt;SonarQube&lt;/strong&gt; scans directly from the IDE. The plugin highlights issues inline and provides quick access to detailed analysis reports. Click &lt;strong&gt;“Analyze All Project Files”&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fx5gj8qn3g223sastwqm.png&quot; alt=&quot;IntelliJ SonarQube plugin analyze project 1&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;You can see the results. In this case, it found the token in the gradle-local.properties file, which is ignored by the &lt;strong&gt;.gitignore file&lt;/strong&gt;, and it is only for local purposes. However, you will still see it unless you exclude it from scanning. This plugin also allows you to do it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ho72wkt45lsdk84kfxb5.png&quot; alt=&quot;IntelliJ SonarQube plugin analyze project 2&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;Below you can see the result of this specific finding. Additionally, the plugin provides information on why this issue occurs and how to resolve it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1wijbjxq9o13918ts2vv.png&quot; alt=&quot;IntelliJ SonarQube plugin analyze project 3&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;Benefits of local scanning:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Immediate feedback on security and quality issues.&lt;/li&gt;
&lt;li&gt;Reduces the likelihood of pushing vulnerable code.&lt;/li&gt;
&lt;li&gt;Saves time by fixing problems early in the development workflow.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;/p&gt;
&lt;h3 id=&quot;local-scanning-using-docker-compose-with-sonarqube-image&quot;&gt;Local scanning using Docker Compose with SonarQube image&lt;/h3&gt;
&lt;p&gt;If you prefer running SonarQube locally, Docker provides an easy setup that eliminates the need for complex installation.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;h4 id=&quot;setting-up-sonarqube-locally-via-docker-compose&quot;&gt;Setting up SonarQube locally via Docker Compose&lt;/h4&gt;
&lt;p&gt;Create a &lt;strong&gt;“docker-compose.yml”&lt;/strong&gt; file with the following content:&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-dockerfile&quot;&gt;    version: &quot;3.9&quot;
    
    
    services:
     sonarqube:
       image: sonarqube:latest
       ports:
         - &quot;9000:9000&quot;
       environment:
         SONAR_ES_BOOTSTRAP_CHECKS_DISABLE: &quot;true&quot;
       volumes:
         - sonarqube_data:/opt/sonarqube/data
         - sonarqube_extensions:/opt/sonarqube/extensions
    
    
    volumes:
     sonarqube_data:
     sonarqube_extensions:

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;Here is the &lt;strong&gt;gradle-local.properties&lt;/strong&gt; file.&lt;/p&gt;
&lt;p&gt;Place it in the root of the project and add it to the &lt;strong&gt;.gitignore&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-properties&quot;&gt;    systemProp.sonar.qualitygate.wait=true
    
    
    sonar.projectKey=sonarqube_actions_demo_key
    sonar.organization=local-organization
    sonar.projectName=sonarqube_actions_demo
    sonar.token=sqp_b7dc6e025b58eb7455b11c6c468cda2b79eb6450b
    sonar.host.url=http://localhost:9000
    sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/test/jacocoTestReport.xml
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;Gradle configuration. The SonarQube plugin is required.&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-gradle&quot;&gt;    plugins {
       id 'java'
       id &quot;org.sonarqube&quot; version &quot;7.0.0.6105&quot;
       id 'jacoco'
       id 'org.springframework.boot' version '3.0.0'
       id 'io.spring.dependency-management' version '1.1.7'
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;SonarQube properties&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-gradle&quot;&gt;    def localProps = new Properties()
    def localFile = file(&quot;gradle-local.properties&quot;)
    if (localFile.exists()) {
    localProps.load(localFile.newDataInputStream())
    }
    
    
    sonar {
    properties {
       property &quot;sonar.projectKey&quot;, System.getenv(&quot;SONAR_PROJECT_KEY&quot;) ?: localProps[&quot;sonar.projectKey&quot;]
       property &quot;sonar.organization&quot;, System.getenv(&quot;SONAR_ORGANIZATION_KEY&quot;) ?: localProps[&quot;sonar.organization&quot;]
       property &quot;sonar.projectName&quot;, System.getenv(&quot;SONAR_PROJECT_NAME&quot;) ?: localProps[&quot;sonar.projectName&quot;]
       property &quot;sonar.token&quot;, System.getenv(&quot;SONAR_TOKEN&quot;) ?: localProps[&quot;sonar.token&quot;]
       property &quot;sonar.host.url&quot;, System.getenv(&quot;SONAR_HOST_URL&quot;) ?: localProps[&quot;sonar.host.url&quot;]
    }
    }

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;Run the following command to start the container: &lt;strong&gt;docker-compose up -d&lt;/strong&gt;, or you can run it from your &lt;strong&gt;IntelliJ IDEA&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lxz9qcxyxzt6kkystdox.png&quot; alt=&quot;IntelliJ Docker-compose icon run&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;You can see the container is up and running&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vuoov0l31qkq5ysvxcyc.png&quot; alt=&quot;IntelliJ Docker container running&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;Access SonarQube dashboard at &lt;a rel=&quot;nofollow&quot; href=&quot;http://localhost:9000&quot;&gt;http://localhost:9000&lt;/a&gt;. Login is &lt;strong&gt;admin&lt;/strong&gt;, but you will need to change the password from admin to a new one.&lt;/p&gt;
&lt;p&gt;Click Create project from the top right corner.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c11kt3pekl595qfyjzh8.png&quot; alt=&quot;Local SonarQube create project menu&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;Enter the same name and project key as in your &lt;strong&gt;gradle-local.properties&lt;/strong&gt; file. Then select to use the previous version.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d7k5hg6efsm6q0z3j293.png&quot; alt=&quot;Local SonarQube create project step 1&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;Choose &lt;strong&gt;Locally&lt;/strong&gt; as the &lt;strong&gt;Analysis Method&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h8db1yzo1hi7kbzhlszf.png&quot; alt=&quot;Local SonarQube create project step 2&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;Type the name of the token and click Generate, then Continue, and set it in the &lt;strong&gt;gradle-local.properties&lt;/strong&gt; file to the &lt;strong&gt;“sonar.token”&lt;/strong&gt; property like &lt;code&gt;`&lt;/code&gt;properties sonar.token=sqp_b7dc6e025b58eb7455b11c6c468cda2b79eb6450b&lt;code&gt;`&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nmhadcx1lhsruvf7aude.png&quot; alt=&quot;Local SonarQube create project token generation step 3&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;If you want to generate manually, you can do it as shown in the screenshot below.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/khfd3jc67ygkut1bukgq.png&quot; alt=&quot;Local SonarQube manual token generation&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h4 id=&quot;run-the-sonar-scan-from-the-command-line-or-from-intellij-idea&quot;&gt;Run the Sonar scan from the command line or from &lt;strong&gt;IntelliJ IDEA&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Use this command  &lt;strong&gt;./gradlew sonar --info&lt;/strong&gt; or run from your &lt;strong&gt;IntelliJ IDEA&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5wp1nc739zdw3hk02gx7.png&quot; alt=&quot;Gradle sonar local scanning command result&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;p&gt;You can view the result by going to the Projects tab. The metrics and coverage are for the main branch only and show overall coverage and metrics. For more details about the new code analysis, click on the project.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iyzj2r3aqdditsq5td15.png&quot; alt=&quot;Local SonarQube result on UI&quot;&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h4 id=&quot;comparing-local-docker-setup-with-cloud-scanning&quot;&gt;Comparing Local Docker Setup with Cloud Scanning&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Cloud: No maintenance, scalable, accessible anywhere.&lt;/li&gt;
&lt;li&gt;Local Docker: Full control, ideal if you have no internet connection for an extended period but need to review scan results, useful for sensitive projects.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3 id=&quot;conclusion-1&quot;&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;This article demonstrates how to maximize the benefits of SonarCloud by scanning locally with IntelliJ IDEA or Docker. This helps prevent insecure code from being pushed even to a feature branch and allows developers to work more productively.&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3 id=&quot;closing&quot;&gt;&lt;strong&gt;Closing&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;This article covered  SonarQube Cloud configuration and IntelliJ IDEA integration, as well as running SonarQube locally with Docker. In &lt;strong&gt;“Automating code security in CI/CD: SonarCloud SAST guide (Part 3)”&lt;/strong&gt;, we will explore practical integration examples, configuration patterns, and &lt;strong&gt;CI/CD&lt;/strong&gt; pipelines.&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3 id=&quot;links&quot;&gt;&lt;strong&gt;Links&lt;/strong&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;SonarQube Cloud - &lt;a rel=&quot;nofollow&quot; href=&quot;https://sonarcloud.io&quot;&gt;https://sonarcloud.io&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;SonarQube documentation - &lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.sonarsource.com&quot;&gt;https://docs.sonarsource.com&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>Tutorials</category>
<guid isPermaLink="true">https://coderlegion.com/9955/catch-vulnerabilities-before-they-ship-local-sonarqube-setup-part-2</guid>
<pubDate>Sun, 18 Jan 2026 14:36:05 +0000</pubDate>
</item>
</channel>
</rss>