-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
Description
Hello,
We’re currently encountering issues with CodeQL / Analyze (javascript-typescript) (dynamic), which fails to run due to syntax errors reported in the analysis output. A file is flagged as unprocessable due to presumed parsing errors. Here’s the code and associated extract of the error messages:
Code:
import React, { useState } from 'react';
import { exec } from 'child_process';
const BadPractices = () => {
const [input, setInput] = useState('');
const [output, setOutput] = useState('');
// Example of using eval (bad practice)
const handleEval = () => {
try {
const result = eval(input); // BAD: Using eval
setOutput(result);
} catch (error: any) {
setOutput('Error: ' + error.message);
}
};
// Example of using exec (bad practice)
const handleExec = () => {
exec(input, (error, stdout, stderr) => {
if (error) {
setOutput('Error: ' + error.message);
return;
}
if (stderr) {
setOutput('Stderr: ' + stderr);
return;
}
setOutput('Output: ' + stdout);
});
};
// Example of insecure direct object reference (IDOR)
const handleInsecureIDOR = () => {
const userId = input; // BAD: Directly using user input
fetch(`/api/user/${userId}`)
.then((response) => response.json())
.then((data) => setOutput(JSON.stringify(data)))
.catch((error) => setOutput('Error: ' + error.message));
};
return (
<div>
<h1>Bad Practices Example</h1>
<input
type="text"
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="Enter input"
/>
<button onClick={handleEval}>Run Eval</button>
<button onClick={handleExec}>Run Exec</button>
<button onClick={handleInsecureIDOR}>Fetch User Data</button>
<div>
<h2>Output</h2>
<pre>{output}</pre>
</div>
</div>
);
};
export default BadPractices;
Logs:
...
Analysis produced the following diagnostic information:
Could not process some files due to syntax errors (23 results)
* app/features/base/components/BadPractices.ts#L44C15:15: A parse error occurred: `')' expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L44C33:33: A parse error occurred: `Unterminated regular expression literal.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L48C19:19: A parse error occurred: `Property assignment expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L48C23:23: A parse error occurred: `';' expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L48C50:50: A parse error occurred: `Declaration or statement expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L50C8:8: A parse error occurred: `Expression expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L51C15:15: A parse error occurred: `'>' expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L51C22:22: A parse error occurred: `';' expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L51C35:35: A parse error occurred: `Expression expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L51C40:40: A parse error occurred: `';' expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L51C45:45: A parse error occurred: `Unterminated regular expression literal.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L52C15:15: A parse error occurred: `';' expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L52C40:40: A parse error occurred: `';' expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L52C45:45: A parse error occurred: `Unterminated regular expression literal.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L53C15:15: A parse error occurred: `';' expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L53C50:50: A parse error occurred: `';' expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L53C60:60: A parse error occurred: `Unterminated regular expression literal.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L55C20:20: A parse error occurred: `Unterminated regular expression literal.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L56C23:23: A parse error occurred: `Unterminated regular expression literal.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L57C8:8: A parse error occurred: `Unterminated regular expression literal.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L58C6:6: A parse error occurred: `Unterminated regular expression literal.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L59C3:3: A parse error occurred: `Declaration or statement expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
* app/features/base/components/BadPractices.ts#L60C1:1: A parse error occurred: `Declaration or statement expected.`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.
...
Environment:
- "productName" : "CodeQL", "vendor" : "GitHub", "version" : "2.19.1",
- CODEQL_ACTION_VERSION: 3.26.13
- /language:javascript-typescript
Context:
This code was intentionally generated (with ChatGPT) to showcase insecure coding practices for a security demonstration. Our objective was to verify if CodeQL would detect these issues. However, CodeQL was unable to parse the file, so no analysis was completed.
Assistance Needed:
- Does the parsing issue lies within CodeQL or are these genuine javascript-typescript syntax errors?
- Is there a repo configuration option to ensure that a push/PR to a branch is blocked if CodeQL encounters errors like these?
- Are there any recommended steps or adjustments we should take to resolve this issue and successfully complete the scan?
Thanks in advance.
Best regards,
tl-admin, abogacz-tl and drmaciej