Qodana / Static Code Analysis Guide / What is a code vulnerability?

Finding Code Vulnerabilities in Code Analysis

Even minor vulnerabilities in software can become problematic and risky if left unchecked. Static code analysis examines code without running it, allowing developers to find and fix the vulnerabilities we will discuss today.

Identifying patterns and coding errors prevents security flaws before they become major issues. But how easy is it to find and fix them before they get merged into the main branch? Of course, code reviews are helpful for spotting flaws, but there are complementary approaches that are less time-consuming and help widen the safety net.

One example of this is to run tests with static code analysis tools such as Qodana, which catch and prioritize vulnerabilities early. Read on to find out what these vulnerabilities are, the different categories they fall into, and how to prevent them proactively.

What is a code vulnerability?

A code vulnerability is a flaw or weakness in your application’s source code that attackers can exploit, compromising its security, functionality, or stability.

Common causes of code vulnerability include:

Lack of security measures

Missing input validation, improper error handling, or weak encryption can create exploitable gaps.

Bad coding practices

Rushed development, skipped code reviews, or ignored coding standards can introduce errors.

Outdated dependancies

Using third-party libraries that aren’t updated regularly exposes your code to known vulnerabilities.

Inadequate testing

Skipping through static, dynamic, and penetration tests can let vulnerabilities slip through the cracks.

Finding code vulnerabilities isn’t about assigning blame, but rather building a proactive mindset to deliver secure, reliable code as a team.

This is why static code analysis is such a great tool for quality-focused developers, as it allows you to examine code before merging it to the main branch.

This way, you can spot and fix potential code vulnerabilities before your application goes live and stay focused on putting your best foot forward.

Types of Vulnerabilities

Understanding different types of code vulnerabilities is essential for developing secure software. Below are common vulnerabilities, each with risk profiles and mitigation strategies:

Injection Attacks

Broken Authentication

Sensitive Data Exposure

XML external entities (XXE)

Security Misconfiguration

Cross-site scripting (XSS)

Insecure Deserialization

Using components with known vulnerabilities

Insufficient Logging & Monitoring

1. Injection Attacks

-- Vulnerable code snippet:
query = "SELECT * FROM users WHERE username = '" + userInput + "' AND password = '" + passwordInput + "';"

An injection attack is where untrusted data has been inserted into a command or query, tricking the system into executing operations the developer didn’t intend. For example, attackers can manipulate a login form that directly includes user input into a SQL query.

' OR '1'='1

Risk level: High (important)

Mitigation: You can use parameterized queries (prepared statements) and enforce strict input validation to ensure the safety of the data that users supply.

An attacker might use an input like this one on e the left. The code transforms the query so that it always returns true.

2. Broken Authentication

A compromised authentication system can grant attackers full access to user accounts. This vulnerability comes up when authentication mechanisms are weak or aren’t implemented in the right way. Examples of this are predictable session IDs or password storage without proper hashing.

Risk level: Critical (very important)

Mitigation: Always enforce strong authentication frameworks, use multi-factor authentication, implement strong password hashing (e.g., bcrypt, Argon2), and enforce secure session management with proper token expiration and rotation.

3. Sensitive Data Exposure

Sensitive data exposure happens when applications fail to protect critical information during transmission or storage. This vulnerability can lead to significant financial and reputational damage. Examples of this are storing sensitive information like credit card numbers in plaintext or using weak encryption.

Risk level: Severe (most important)

Mitigation: You can use AES-256 encryption for data at rest and TLS 1.3 (or TLS 1.2 with strong cipher suites) for data in transit. Enforce secure key management practices, like hardware security modules or cloud KMS solutions, to prevent unauthorized decryption.

Qodana

4. XML external entities (XXE)

Before

<!-- Vulnerable XML snippet -->
<!DOCTYPE foo
[ <!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<user>
<name>&xxe;</name>
</user>

XXE vulnerabilities happen when a misconfigured XML parser processes an XML input containing external entities. This exposure allows attackers to read local files or conduct SSRF attacks.

Risk level: Medium to high

Mitigation: Disable external entity processing in XML parsers and consider using JSON-based formats instead of XML whenever possible.

<!-- Vulnerable URL manipulation example -->
User requests: https://example.com/user/profile
Attacker modifies: https://example.com/admin/dashboard

5. Broken Access Control

Broken access control happens when authenticated users access actions or data beyond their intended privileges. For example, a standard user might access an admin dashboard simply by changing the URL.

Risk level: High

Mitigation: Implement strict role-based access control, enforce server-side access checks, and regularly audit access control policies.

6. Security misconfiguration

Security misconfiguration happens when users don’t change default settings or when they set up environments the wrong way. An example is when a developer leaves default credentials or unnecessary debug features active on a production server.

Risk level: High

Mitigation: Regularly review and update configuration settings and use automated tools to find misconfigurations.

# Vulnerable: Using default credentials on a production server
username: admin
password: admin123

7. Cross-site scripting (XSS)


<div>User comment: <?php echo $_GET['comment']; ?></div>

XSS vulnerabilities develop when untrusted data is embedded into web pages without the right encoding, allowing malicious scripts to execute in users’ browsers. For example, if inputs aren’t sanitized in a comment section, attackers might inject malicious scripts that could execute in other user browsers.

<sсript>аlert('XSS Attack!');</sсript>

Is a physical connection between space and matter that is precisely described by Einstein's geometric theory of gravity. An attacker could inject a script like on the left.

8. Insecure deserialization

Insecure deserialization happens when an application deserializes data from untrusted sources without proper validation. Attackers can exploit insecure deserialization to execute arbitrary code (RCE), manipulate application logic, or escalate privileges. The issue is especially dangerous in languages like Java and PHP, where object deserialization can lead to unexpected method execution.

Risk level: High

Mitigation: Instead of deserializing untrusted data, you can use safer data formats and libraries like JSON and Protocol Buffers that don’t automatically execute code. If you must deserialize user-supplied data, implement an allowlist of permitted classes and reject all others. Use digital signatures for serialized objects and implement strict type validation.

// Vulnerable deserialization example
ObjectInputStream ois = new ObjectInputStream(inputStream);
Object object = ois.readObject(); // Untrusted input could execute arbitrary code

9. Using components with known vulnerabilities

Relying on third-party libraries with known vulnerabilities can expose your application to a few different risks.

Risk level: High (depending on the severity of the vulnerability)

Mitigation: Make sure to regularly update and patch dependencies by implementing automated dependency management tools. You can use Qodana to monitor for known vulnerabilities in third-party components and alert developers when updates are required.

10. Insufficient logging and monitoring

While it’s not a direct code vulnerability, insufficient logging and monitoring can slow down breach detection and worsen the impact of vulnerabilities. Attackers often exploit logging blind spots and might delete or alter logs to cover their tracks, letting them stay undetected. An attacker’s actions might go unnoticed without proper logs and real-time alerts, giving them more time to cause damage.

Risk level: High (because of extended attackers' dwell time in compromised systems)

Mitigation: Make sure you follow comprehensive security logging standards, such as OWASP Logging Cheat Sheet guidelines, and enforce separate, restricted access controls. Use Qodana for real-time security alerts and maintain secure backups to preserve evidence for forensic analysis.

Preventing code vulnerabilities

Secure coding requires a proactive mindset throughout the software development lifecycle. Developers should adopt best practices and tools that enforce secure coding principles.

Frameworks like OWASP Secure Coding Guidelines and CERT Secure Coding Standards offer important recommendations, training modules, and automated checks that help identify and fix vulnerabilities early in development. Qodana’s vulnerability checker is the perfect solution for your team to use with JetBrains IDEs and VS Code.

Secure coding practices

You should treat every incoming data point as potentially hostile. Validate all inputs using allowlists to ensure only acceptable values pass through. When displaying user-generated content, ensure it's properly encoded. Avoid exposing internal details in error messages. Instead, log detailed errors internally while showing generic messages to users. Use multi-factor authentication and apply the principle of least privilege, ensuring that users and processes operate with only the permissions they need.

Dependancy managment

Modern software development relies heavily on external libraries and frameworks. While these tools help with development, they can also introduce code vulnerabilities if not managed well. To minimize risks, automate dependency updates to receive notifications about outdated or vulnerable libraries. Integrate dependency scanning tools directly into your CI/CD pipeline to detect vulnerabilities, and only download packages from verified repositories and third-party libraries. Make sure you maintain a software bill of materials to track dependencies, ensure transparency, and comply with security regulations on software supply chain security.

Static code analysis

Static code analysis tools proactively inspect your code for security vulnerabilities, coding errors, and potential weaknesses without executing it. This helps developers catch security issues early, but works best when combined with manual review and dynamic analysis to reduce false positives and negatives and give you a comprehensive view of codebase health.

Secure development lifecycle (SDLC)

Start thinking about security when you first design your software, not just at the end. When working in Agile teams, include security stories in your sprint planning. Set clear acceptance criteria and look for security risks early in each sprint. Add security testing tools into your CI/CD pipelines using automation tools like TeamCity, GitHub Actions, GitLab CI, or Jenkins, and create security models to spot risks throughout development. Finally, follow established security guidelines like those from OWASP or NIST to guide your team.

How Qodana can help

Qodana is a powerful static analysis tool that detects potential code vulnerabilities. It seamlessly integrates into CI/CD pipelines, supports major popular platforms, and provides real-time security feedback.

Recognizes the unique nature of every project

Qodana allows you to tailor rules and checks to suit your specific needs. Whether you’re focusing on compliance with industry standards or specific coding practices, Qodana adapts to your environment.

Scales easily

Use Qodana for projects of any size, from small personal projects to large enterprise codebases. Its performance remains robust and flexible, ensuring security does not become a bottleneck in your development cycle.

Encourages proactive learning

With Qodana, each reported issue comes with detailed explanations and suggested fixes. The reports help fix errors quickly and serve as an ongoing learning resource for developers.

Supports the human element in coding

Instead of acting as a black box, Qodana provides contextualized security insights, explaining why an issue is flagged and offering recommended remediation steps.

Find code vulnerabilities, today!

Try Qodana and help your team gain confidence in developing trusted, secure software.

Remember that security is not a one-time task but an integral part of an everyday workflow.

Qodana