~/tutorials/resolving-checkmarx-issues-reported.md

Resolving Checkmarx issues reported

1 min readJune 03, 2018by Gorav Singal#checkmarx#code-analysis
// TL;DR

Fix Checkmarx security findings by normalizing user input strings before use, applying proper validation and sanitization patterns to avoid flagged vulnerabilities.

Resolving Checkmarx issues reported

Unnormalize Input String

It complains that you are using input string argument without normalize.
By normalizing means, do some refinement of the input. The rule says, never trust user input. Always do some check on that, and normalize them.

Faulty code:

``` public static void main(String[] args) throws Exception{ Strings x = args[0]; //use x } ```

So, here we are using input variable String[] args without any validation/normalization

Java provides Normalize API. See example below:

String s = java.text.Normalizer.normalize(args[0], java.text.Normalizer.Form.NFKC);

By doing so, you are ensuring that you have normalize the user input, and are not using it directly.

Input path not canocalized

We are working on a system or disk path, which can expose unexpected files to users. If you are accepting a path from user, and you use it directly. Or, even if you are checking it. The path may be a sym link, or relative path (having .. in it). You might completely skip the validation.

In this case, it suggests you to use canonicalized paths. See example below:

String path = System.getProperty("java.io.tmpdir");
File file = new File(path);
path = file.getCanonicalPath();

Unchecked condition for loop condition

Your code is taking user input in a variable and that variable is directly being used in a loop condition. Solution is to put an input validation.

$ subscribe --weekly

One deep dive a week, in your inbox

System design, AI engineering, trading systems and interview prep. Tested code, real numbers. Free, and you can unsubscribe any time.

or read it on gyanbyte.substack.com

Share

Related Posts

Claude Code Skills — Build a Better Engineering Workflow

Claude Code Skills — Build a Better Engineering Workflow

Most developers use Claude Code like a search engine — ask a question, get an…

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

How to Be a Full-Time Freelancer: Resources, Finding Clients, and Building a Sustainable Business

How to Be a Full-Time Freelancer: Resources, Finding Clients, and Building a Sustainable Business

Making the leap from full-time employment to freelancing is one of the most…

Jenkins Pipeline with Jenkinsfile - How To Schedule Job on Cron and Not on Code Commit

Jenkins Pipeline with Jenkinsfile - How To Schedule Job on Cron and Not on Code Commit

Introduction In this post we will see following: How to schedule a job on cron…

How to Git Clone Another Repository from Jenkin Pipeline in Jenkinsfile

How to Git Clone Another Repository from Jenkin Pipeline in Jenkinsfile

Introduction There are some cases, where I need another git repository while…

Latest Posts

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

In the previous article I argued that AI is not killing software engineering…

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

A few months back I approved a PR that was almost entirely AI-generated. It…

How to Debug AI-Generated Code: Understand First, Fix Last

How to Debug AI-Generated Code: Understand First, Fix Last

In the last article I wrote about reviewing AI code before it goes in. This one…

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

Every few weeks somebody sends me a scary headline — “AI will replace all…

The Transactional Outbox Pattern: Never Lose an Event Again

The Transactional Outbox Pattern: Never Lose an Event Again

This is one of those patterns that looks like nothing until you get burnt once…

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Here is a question I like to ask in interviews: your bank account shows a…