Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .codacy/codacy.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
runtimes:
- dart@3.7.2
- go@1.22.3
- java@17.0.10
- node@22.2.0
- python@3.11.11
tools:
- codacy-enigma-cli@0.0.1-main.8.49310c3
- dartanalyzer@3.7.2
- eslint@8.57.0
- eslint@9.26.0
- lizard@1.17.19
- pmd@6.55.0
- pylint@3.3.6
- pmd@7.11.0
- pylint@3.3.7
- revive@1.7.0
- semgrep@1.78.0
- trivy@0.59.1
9 changes: 0 additions & 9 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,6 @@ func validatePaths(paths []string) error {
return nil
}

func validateCloudMode(cliLocalMode bool) error {
if cliLocalMode {
fmt.Println("Warning: cannot run in cloud mode")
}
return nil
}

var analyzeCmd = &cobra.Command{
Use: "analyze",
Short: "Analyze code using configured tools",
Expand All @@ -465,8 +458,6 @@ Supports API token, provider, and repository flags to automatically fetch tool c

cliLocalMode := len(initFlags.ApiToken) == 0

validateCloudMode(cliLocalMode)

var toolsToRun map[string]*plugins.ToolInfo

if toolsToAnalyzeParam != "" {
Expand Down
60 changes: 60 additions & 0 deletions example_1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// vulneravel.ts

Check failure on line 1 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L1

Resolve error: package.json not found in path at findRoot (/node_modules/find-root/index.js:19:11) at findRoot (/node_modules/find-root/index.js:28:10) at findRoot (/node_modules/find-root/index.js:28:10) at findRoot (/node_modules/find-root/index.js:28:10) at findRoot (/node_modules/find-root/index.js:28:10) at exports.resolve (/node_modules/eslint-import-resolver-webpack/index.js:76:20) at withResolver (/node_modules/eslint-module-utils/resolve.js:121:23) at fullResolve (/n

import * as http from 'http';
import * as url from 'url';
import * as fs from 'fs';
import * as mysql from 'mysql';

Check failure on line 6 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L6

Can't resolve 'mysql' in '/src'

// 1. Exposição de credenciais
const db = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'rootpassword', // Credenciais expostas
database: 'test'
});

http.createServer((req, res) => {
const parsedUrl = url.parse(req.url || '', true);

Check failure on line 17 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L17

'url.parse' was deprecated since v11.0.0. Use 'url.URL' constructor instead.

Check warning on line 17 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L17

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Prefer using nullish coalescing operator (??) instead of a logical or (||), as it is a safer operator.

Suggested change
const parsedUrl = url.parse(req.url || '', true);
const parsedUrl = url.parse(req.url ?? '', true);

const query = parsedUrl.query;

// 2. Injeção SQL - FIXED: Use parameterized query
const username = query.username;
const sql = `SELECT * FROM users WHERE username = ?`;
db.query(sql, [username], (err, result) => {
if (err) throw err;

// 3. Exposição de dados sensíveis - FIXED: Filter sensitive fields
const safeResult = result.map((user: any) => {

Check warning on line 27 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L27

Unexpected any. Specify a different type.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: Unexpected any. Specify a different type.

Suggested change
const safeResult = result.map((user: any) => {
const safeResult = result.map((user: unknown) => {

const { password, ...safeUser } = user;

Check failure on line 28 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L28

'password' is assigned a value but never used.

Check failure on line 28 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L28

'password' is assigned a value but never used.

Check failure on line 28 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L28

'password' is assigned a value but never used.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codacy has a fix for the issue: 'password' is assigned a value but never used.

Suggested change
const { password, ...safeUser } = user;
const { ...safeUser } = user;

return safeUser;
});
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(safeResult)); // devolve dados sem campos sensíveis
});

// 4. Leitura insegura de ficheiros
const file = query.file as string;
fs.readFile('./uploads/' + file, 'utf8', (err, data) => {

Check warning on line 37 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L37

Detected that function argument `req` has entered the fs module.

Check warning on line 37 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L37

Found readFile from package "fs" with non literal argument at index 0

Check warning on line 37 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L37

Found readFile from package "fs" with non literal argument at index 0
if (!err) {
res.write('\n\n' + data); // pode ser usado para leitura arbitrária de ficheiros
}
});

// 5. Execução de código arbitrário
if (query.runCode) {
eval(query.runCode as string); // MUITO perigoso

Check warning on line 45 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L45

Detected the use of eval(). eval() can be dangerous if used to evaluate dynamic content.

Check failure on line 45 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L45

The application was found calling the `eval` function OR Function() constructor OR setTimeout() OR setInterval() methods.

Check warning on line 45 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L45

detect eval() with non Literal argument

Check warning on line 45 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L45

detect eval() with non Literal argument

Check warning on line 45 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L45

eval with argument of type TSAsExpression

Check warning on line 45 in example_1.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

example_1.ts#L45

eval with argument of type TSAsExpression
}

}).listen(8080);

// 6. Dependência desatualizada (suponha que mysql está vulnerável)

// 7. Falta de HTTPS (http em vez de https)

// 8. Nenhuma validação de entrada em nenhuma parte

// 9. Stack traces revelados com throw err

// 10. Não existe autenticação nem controlo de acessos

console.log('Servidor inseguro a correr em http://localhost:8080');
146 changes: 146 additions & 0 deletions out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
Warning: cannot run in cloud mode
{
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
"runs": [
{
"invocations": [
{
"executionSuccessful": true,
"toolExecutionNotifications": []
}
],
"results": [],
"tool": {
"driver": {
"name": "Semgrep OSS",
"rules": null,
"semanticVersion": "1.78.0"
}
}
},
{
"columnKind": "utf16CodeUnits",
"originalUriBaseIds": {
"ROOTPATH": {
"uri": "file:///Users/czak/GIT/codacy/codacy-cli-v2/example_1.ts/"
}
},
"results": [],
"tool": {
"driver": {
"fullName": "Trivy Vulnerability Scanner",
"informationUri": "https://github.com/aquasecurity/trivy",
"name": "Trivy",
"rules": null,
"version": "0.59.1"
}
}
},
{
"artifacts": [
{
"location": {
"uri": "file:///Users/czak/GIT/codacy/codacy-cli-v2/example_1.ts"
}
}
],
"invocations": [
{
"executionSuccessful": true,
"toolConfigurationNotifications": [
{
"descriptor": {
"id": "ESL0999"
},
"level": "warning",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"index": 0,
"uri": "file:///Users/czak/GIT/codacy/codacy-cli-v2/example_1.ts"
}
}
}
],
"message": {
"text": "File ignored because no matching configuration was supplied."
}
}
]
}
],
"results": [],
"tool": {
"driver": {
"informationUri": "https://eslint.org",
"name": "ESLint",
"rules": null,
"version": "9.26.0"
}
}
},
{
"results": [
{
"level": "error",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "example_1.ts"
},
"region": {
"startColumn": 1,
"startLine": 1
}
}
}
],
"message": {
"text": "Parsing failed: 'invalid syntax (example_1, line 1)'"
},
"ruleId": "syntax-error"
}
],
"tool": {
"driver": {
"informationUri": "https://pylint.org",
"name": "Pylint",
"rules": null,
"version": "3.3.6"
}
}
},
{
"results": [
{
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "example_1.ts"
},
"region": {
"startColumn": 1,
"startLine": 3
}
}
}
],
"message": {
"text": "invalid file example_1.ts: example_1.ts:3:1: expected 'package', found 'import' (and 4 more errors)"
}
}
],
"tool": {
"driver": {
"informationUri": "https://github.com/mgechev/revive",
"name": "revive",
"rules": null
}
}
}
],
"version": "2.1.0"
}
Empty file added req.txt
Empty file.
20 changes: 20 additions & 0 deletions vul.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


// 5. Execução de código arbitrário
if (query.runCode) {
eval(query.runCode as string); // MUITO perigoso

Check warning on line 5 in vul.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

vul.ts#L5

Detected the use of eval(). eval() can be dangerous if used to evaluate dynamic content.

Check failure on line 5 in vul.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

vul.ts#L5

The application was found calling the `eval` function OR Function() constructor OR setTimeout() OR setInterval() methods.
}

}).listen(8080);

// 6. Dependência desatualizada (suponha que mysql está vulnerável)

// 7. Falta de HTTPS (http em vez de https)

// 8. Nenhuma validação de entrada em nenhuma parte

// 9. Stack traces revelados com throw err

// 10. Não existe autenticação nem controlo de acessos

console.log('Servidor inseguro a correr em http://localhost:8080');