Avoid code injection | CAST Appmarq

Avoid code injection

CRITICAL

Rule Definition
The software constructs all or part of a dynamic evaluation using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended code when it is sent to a downstream component. This could allow attackers to execute unexpected, dangerous commands directly on the operating system. This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system, such as in web applications.

Remediation
Assume all input is malicious. Avoid using inputs. If it is not possible, use an "accept known good" input validation strategy, i.e., use stringent white-lists that limit the character set based on the expected value of the parameter in the request. This will indirectly limit the scope of an attack.

Violation Code Sample
using Microsoft.CodeAnalysis.CSharp.Scripting;
...
var value = CSharpScript.Eval("1 + 2 + " + fromUser);
Console.Write(value); // 3 + ?
Fixed Code Sample
using Microsoft.CodeAnalysis.CSharp.Scripting;
...
var value = CSharpScript.Eval("1 + 2");
Console.Write(value); // 3

Reference
CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') https://cwe.mitre.org/data/definitions/78.html Open Web Application Security Project (OWASP) https://www.owasp.org/index.php/Top_10_2007 CISQ: ASCSM-CWE-078

Related Technologies

Health Factor

  Security


Technical Criterion
CWE-95 - Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')

About CAST Appmarq

CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.

Benchmark Statistics

Global Compliance

nan%

Total Violations
0
Total Opportunities
0
Average Violations / App.
nan
The compliance score represents 1 minus the ratio between the number of times a rule has been violated compared to the number of opportunities in a set of applications that the rule could have been violated.

Industry Insights

Select from drop-down

100.00%

Don't Know

100.00%

Energy

100.00%