Skip to content

Commit 09fe7b8

Browse files
Merge pull request #8 from codacy/add-key-keyword-secret-detection
Add key keyword secret detection
2 parents 9ceedb1 + 060de53 commit 09fe7b8

File tree

9 files changed

+29
-10
lines changed

9 files changed

+29
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Codacy Semgrep
1+
# Codacy Opengrep
22

33
This is the docker engine we use at Codacy to have [Opengrep](https://github.com/opengrep/opengrep) support.
44

docs/codacy-rules.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ rules:
2525
- pattern: String $PASSWORD = "$VALUE";
2626
- metavariable-regex:
2727
metavariable: "$PASSWORD"
28-
regex: "(?i).*(password|motdepasse|heslo|adgangskode|wachtwoord|salasana|passwort|passord|senha|geslo|clave|losenord|clave|parola|secret|pwd).*"
28+
regex: "(?i).*(password|motdepasse|heslo|adgangskode|wachtwoord|salasana|passwort|passord|senha|geslo|clave|losenord|clave|parola|secret|pwd|key).*"
2929
message: Hardcoded passwords are a security risk. They can be easily found by attackers and used to gain unauthorized access to the system.
3030
metadata:
3131
owasp:
@@ -45,7 +45,7 @@ rules:
4545
- pattern: var $PASSWORD = "$VALUE";
4646
- metavariable-regex:
4747
metavariable: "$PASSWORD"
48-
regex: "(?i).*(password|motdepasse|heslo|adgangskode|wachtwoord|salasana|passwort|passord|senha|geslo|clave|losenord|clave|parola|secret|pwd).*"
48+
regex: "(?i).*(password|motdepasse|heslo|adgangskode|wachtwoord|salasana|passwort|passord|senha|geslo|clave|losenord|clave|parola|secret|pwd|key).*"
4949
message: Hardcoded passwords are a security risk. They can be easily found by attackers and used to gain unauthorized access to the system.
5050
metadata:
5151
owasp:
@@ -74,7 +74,7 @@ rules:
7474
- pattern: var $PASSWORD = `$VALUE`
7575
- metavariable-regex:
7676
metavariable: "$PASSWORD"
77-
regex: "(?i).*(password|motdepasse|heslo|adgangskode|wachtwoord|salasana|passwort|passord|senha|geslo|clave|losenord|clave|parola|secret|pwd).*"
77+
regex: "(?i).*(password|motdepasse|heslo|adgangskode|wachtwoord|salasana|passwort|passord|senha|geslo|clave|losenord|clave|parola|secret|pwd|key).*"
7878
message: Hardcoded passwords are a security risk. They can be easily found by attackers and used to gain unauthorized access to the system.
7979
metadata:
8080
owasp:
@@ -105,7 +105,7 @@ rules:
105105
$PASSWORD VARCHAR2($LENGTH) := $...VALUE;
106106
- metavariable-regex:
107107
metavariable: "$PASSWORD"
108-
regex: "(?i).*(password|motdepasse|heslo|adgangskode|wachtwoord|salasana|passwort|passord|senha|geslo|clave|losenord|clave|parola|secret|pwd).*"
108+
regex: "(?i).*(password|motdepasse|heslo|adgangskode|wachtwoord|salasana|passwort|passord|senha|geslo|clave|losenord|clave|parola|secret|pwd|key).*"
109109
options:
110110
generic_ellipsis_max_span: 0
111111
message: >

docs/multiple-tests/codacy-rules-java/results.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<checkstyle version="1.5">
33
<file name="Program.java">
44
<error source="codacy.java.security.hard-coded-password" line="8" message="Hardcoded passwords are a security risk." severity="error" />
5-
<error source="codacy.java.security.flexible-search-sql-injection" line="9" message="Possible SQL Injection: Avoid concatenating user input in FlexibleSearchQuery." severity="error" />
5+
<error source="codacy.java.security.hard-coded-password" line="9" message="Hardcoded passwords are a security risk." severity="error" />
6+
<error source="codacy.java.security.hard-coded-password" line="10" message="Hardcoded passwords are a security risk." severity="error" />
7+
<error source="codacy.java.security.flexible-search-sql-injection" line="11" message="Possible SQL Injection: Avoid concatenating user input in FlexibleSearchQuery." severity="error" />
68
</file>
79
</checkstyle>

docs/multiple-tests/codacy-rules-java/src/Program.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ class Program
66
public static void main(String[] args)
77
{
88
private static final String PASSWORD = "password" ; // Issue: Hardcoded password
9+
private static final String API_KEY = "api_key" ; // Issue: Hardcoded API key
10+
private static final String API_SECRET = "api_secret" ; // Issue: Hardcoded API secret
911
final FlexibleSearchQuery query = new FlexibleSearchQuery("SELECT {a.pk} FROM {TEST AS a} WHERE {a.uid} ="+ uid +" AND {a.visibleInAddressBook} = true");
1012

1113
final FlexibleSearchQuery okquery = new FlexibleSearchQuery(
1214
"SELECT {a.pk} FROM {TEST AS a} WHERE {a.uid} = ?uid AND {a.visibleInAddressBook} = true"
1315
);
1416
okquery.addQueryParameter("uid", uid);
1517
System.out.println("This is a security risk: " + PASSWORD);
18+
System.out.println("This is a security risk: " + API_KEY);
19+
System.out.println("This is a security risk: " + API_SECRET);
1620
}
1721
}
1822

docs/multiple-tests/codacy-rules-javascript/results.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
<error source="codacy.javascript.security.hard-coded-password" line="3" message="Hardcoded passwords are a security risk." severity="error" />
55
<error source="codacy.javascript.security.hard-coded-password" line="4" message="Hardcoded passwords are a security risk." severity="error" />
66
<error source="codacy.javascript.security.hard-coded-password" line="5" message="Hardcoded passwords are a security risk." severity="error" />
7+
<error source="codacy.javascript.security.hard-coded-password" line="6" message="Hardcoded passwords are a security risk." severity="error" />
8+
<error source="codacy.javascript.security.hard-coded-password" line="7" message="Hardcoded passwords are a security risk." severity="error" />
79
</file>
810
</checkstyle>

docs/multiple-tests/codacy-rules-javascript/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ function main(args) {
33
var PASSWORD = "password"; // Issue: Hardcoded password
44
let salasana = 'YAY'
55
const senha = `senha`;
6+
const API_KEY = "api_key"; // Issue: Hardcoded API key
7+
const API_SECRET = "api_secret"; // Issue: Hardcoded API secret
68

79

810
const letPassword = password();

docs/multiple-tests/codacy-rules/results.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
<checkstyle version="1.5">
33
<file name="codacy-csharp-security-hard-coded-password.cs">
44
<error source="codacy.csharp.security.hard-coded-password" line="9" message="Hardcoded passwords are a security risk." severity="error" />
5-
<error source="codacy.csharp.security.null-dereference" line="23" message="Potential null dereference detected." severity="error" />
6-
<error source="codacy.csharp.security.null-dereference" line="26" message="Potential null dereference detected." severity="error" />
7-
<error source="codacy.csharp.security.null-dereference" line="26" message="Potential null dereference detected." severity="error" />
5+
<error source="codacy.csharp.security.hard-coded-password" line="10" message="Hardcoded passwords are a security risk." severity="error" />
6+
<error source="codacy.csharp.security.null-dereference" line="25" message="Potential null dereference detected." severity="error" />
7+
<error source="codacy.csharp.security.null-dereference" line="28" message="Potential null dereference detected." severity="error" />
8+
<error source="codacy.csharp.security.null-dereference" line="28" message="Potential null dereference detected." severity="error" />
89
</file>
910
<file name="test_find_all_passwords_and_empty_string.pls">
10-
<error source="codacy.generic.plsql.empty-strings" line="29" message="Empty strings can lead to unexpected behavior and should be handled carefully." severity="warning" />
11+
<error source="codacy.generic.plsql.empty-strings" line="33" message="Empty strings can lead to unexpected behavior and should be handled carefully." severity="warning" />
1112
<error source="codacy.generic.plsql.find-all-passwords" line="6" message="Hardcoded or exposed passwords are a security risk." severity="error" />
1213
<error source="codacy.generic.plsql.find-all-passwords" line="7" message="Hardcoded or exposed passwords are a security risk." severity="error" />
1314
<error source="codacy.generic.plsql.find-all-passwords" line="8" message="Hardcoded or exposed passwords are a security risk." severity="error" />
15+
<error source="codacy.generic.plsql.find-all-passwords" line="9" message="Hardcoded or exposed passwords are a security risk." severity="error" />
16+
<error source="codacy.generic.plsql.find-all-passwords" line="10" message="Hardcoded or exposed passwords are a security risk." severity="error" />
1417
</file>
1518
<file name="test_resource_injection.pls">
1619
<error source="codacy.generic.plsql.resource-injection" line="16" message="Resource injection detected." severity="error" />

docs/multiple-tests/codacy-rules/src/codacy-csharp-security-hard-coded-password.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ class Program
77
static void Main(string[] args)
88
{
99
var password = "password"; // Issue: Hardcoded password
10+
var api_key = "api_key"; // Issue: Hardcoded API key
1011

1112
Console.WriteLine("This is a security risk: " + password);
13+
Console.WriteLine("This is a security risk: " + api_key);
1214
}
1315

1416
public static bool? IsRegular(bool freqNoneOrNotPeriodic, bool freqPeriodical, IFrequency frequency)

docs/multiple-tests/codacy-rules/src/test_find_all_passwords_and_empty_string.pls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ CREATE OR REPLACE PACKAGE find_passwords AS
66
password1 VARCHAR2(100) := 'Password123!';
77
password2 VARCHAR2(100) := 'Admin@456';
88
password3 VARCHAR2(100) := 'UserPass789';
9+
API_KEY VARCHAR2(100) := 'newAPI_KEY43432';
10+
API_SECRET VARCHAR2(100) := 'newAPI_SECRET43432';
911

1012
-- Procedure to output passwords
1113
PROCEDURE output_passwords;
@@ -19,6 +21,8 @@ BEGIN
1921
DBMS_OUTPUT.PUT_LINE('Password1: ' || password1);
2022
DBMS_OUTPUT.PUT_LINE('Password2: ' || password2);
2123
DBMS_OUTPUT.PUT_LINE('Password3: ' || password3);
24+
DBMS_OUTPUT.PUT_LINE('Password4: ' || API_KEY);
25+
DBMS_OUTPUT.PUT_LINE('Password5: ' || API_KEY);
2226
END output_passwords;
2327
END find_passwords;
2428
/

0 commit comments

Comments
 (0)