Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Published Rules - harishumasankar18_personal_org.detect-new-function #3526

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions harishumasankar18_personal_org/detect-new-function.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

const calculate = (activity, health, weight, happiness) => {
return new Promise(async (resolve, reject) => {
try {
// devine formula :100:
let res = `with(a='${activity}', hp=${health}, w=${weight}, hs=${happiness}) {
if (a == 'feed') { hp += 1; w += 5; hs += 3; } if (a == 'play') { w -= 5; hp += 2; hs += 3; } if (a == 'sleep') { hp += 2; w += 3; hs += 3; } if ((a == 'feed' || a == 'sleep' ) && w > 70) { hp -= 10; hs -= 10; } else if ((a == 'feed' || a == 'sleep' ) && w < 40) { hp += 10; hs += 5; } else if (a == 'play' && w < 40) { hp -= 10; hs -= 10; } else if ( hs > 70 && (hp < 40 || w < 30)) { hs -= 10; } if ( hs > 70 ) { m = 'kissy' } else if ( hs < 40 ) { m = 'cry' } else { m = 'awkward'; } if ( hs > 100) { hs = 100; } if ( hs < 5) { hs = 5; } if ( hp < 5) { hp = 5; } if ( hp > 100) { hp = 100; } if (w < 10) { w = 10 } return {m, hp, w, hs}
}`;
quickMaths = new Function(res);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
quickMaths = new Function(res);
//ruleid: detect-new-function
quickMaths = new Function(res);

const {m, hp, w, hs} = quickMaths();
resolve({mood: m, health: hp, weight: w, happiness: hs})
}
catch (e) {
reject(e);
}
});
}

module.exports = {
calculate
}
24 changes: 24 additions & 0 deletions harishumasankar18_personal_org/detect-new-function.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
rules:
- id: detect-new-function
languages:
- javascript
severity: ERROR
message: |
Using `new Function(...)` can lead to potential security vulnerabilities like arbitrary code execution. Avoid using it.
pattern: |
new Function(...)
metadata:
category: security
confidence: MEDIUM
likelihood: LOW
impact: LOW
cwe:
- 'CWE 94: Improper Control of Generation of Code (''Code Injection'')'
owasp:
- A3:2021 Injection
technology:
- javascript
references:
- https://nvd.nist.gov/vuln/detail/cve-2023-23623
subcategory:
- guardrail
Comment on lines +15 to +24
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cwe:
- 'CWE 94: Improper Control of Generation of Code (''Code Injection'')'
owasp:
- A3:2021 Injection
technology:
- javascript
references:
- https://nvd.nist.gov/vuln/detail/cve-2023-23623
subcategory:
- guardrail
cwe:
- 'CWE-94: Improper Control of Generation of Code (''Code Injection'')'
owasp:
- A3:2021 Injection
technology:
- javascript
references:
- https://nvd.nist.gov/vuln/detail/cve-2023-23623
subcategory:
- secure default

Loading