Skip to content

Commit

Permalink
Merge pull request #3290 from semgrep/merge-develop-to-release
Browse files Browse the repository at this point in the history
Merge Develop into Release
  • Loading branch information
kurt-r2c authored Jan 26, 2024
2 parents de20f54 + b9e6a86 commit 7d3b490
Show file tree
Hide file tree
Showing 18 changed files with 173 additions and 118 deletions.
60 changes: 60 additions & 0 deletions csharp/lang/security/injections/os-command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,65 @@ public void RunConstantAppWithArgs(string args)
// ok: os-command-injection
var process = Process.Start(processStartInfo);
}

public void RunOsCommandAndArgsWithProcessParam(string command, string arguments)
{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = command,
Arguments = args
}
};

// ruleid: os-command-injection
process.Start();
}

public void RunOsCommandAndArgsWithProcessParam(string command, string arguments)
{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "constant",
Arguments = arguments
}
};

// ruleid: os-command-injection
process.Start();
}

public void RunOsCommandAndArgsWithProcessParam(string command, string arguments)
{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = command,
Arguments = "constant"
}
};

// ruleid: os-command-injection
process.Start();
}

public void RunOsCommandAndArgsWithProcessParam(string command, string arguments)
{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "constant",
Arguments = "constant"
}
};

// ok: os-command-injection
process.Start();
}
}
}
19 changes: 19 additions & 0 deletions csharp/lang/security/injections/os-command.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,22 @@ rules:
- pattern: |
Process.Start($PSINFO);
- focus-metavariable: $PSINFO
- patterns:
- pattern-inside: |
Process $PROC = new Process()
{
StartInfo = new ProcessStartInfo()
{
...
}
};
...
- pattern-either:
- pattern-inside: |
FileName = $ARG;
...
- pattern-inside: |
Arguments = $ARG;
...
- pattern: |
$PROC.Start();
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public void BadDocumentBuilderFactory() throws ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
//ruleid:documentbuilderfactory-disallow-doctype-decl-missing
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.newDocumentBuilder();
dbf.newDocumentBuilder();
}

public void BadDocumentBuilderFactory2() throws ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("somethingElse", true);
//ruleid:documentbuilderfactory-disallow-doctype-decl-missing
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.newDocumentBuilder();
dbf.newDocumentBuilder();
}
}

Expand All @@ -77,7 +77,7 @@ class BadDocumentBuilderFactoryStatic {
public void doSomething(){
//ruleid:documentbuilderfactory-disallow-doctype-decl-missing
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.newDocumentBuilder();
dbf.newDocumentBuilder();
}

}
Expand Down Expand Up @@ -115,7 +115,7 @@ public void GoodDocumentBuilderFactory(boolean condition) throws ParserConfigur
}
//ruleid:documentbuilderfactory-disallow-doctype-decl-missing
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.newDocumentBuilder();
dbf.newDocumentBuilder();
}

private DocumentBuilderFactory newFactory(){
Expand Down
12 changes: 0 additions & 12 deletions php/lang/security/non-literal-header.php

This file was deleted.

29 changes: 0 additions & 29 deletions php/lang/security/non-literal-header.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion python/django/security/audit/unvalidated-password.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rules:
- pattern: $MODEL.set_password($X)
fix: >
if django.contrib.auth.password_validation.validate_password($X, user=$MODEL):
$MODEL.set_password($X)
$MODEL.set_password($X)
message: >-
The password on '$MODEL' is being set without validating the password.
Call django.contrib.auth.password_validation.validate_password() with
Expand Down
5 changes: 5 additions & 0 deletions python/lang/correctness/list-modify-iterating.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@
for i in e:
print(i)
d.append(i)

# ruleid:list-modify-while-iterate
for i in e:
if i == 1:
e.remove(i)
6 changes: 6 additions & 0 deletions python/lang/correctness/list-modify-iterating.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ rules:
for $ELEMENT in $LIST:
...
$LIST.extend(...)
- pattern: |
for $ELEMENT in $LIST:
...
$LIST.remove(...)
metadata:
category: correctness
technology:
- python
references:
- https://unspecified.wordpress.com/2009/02/12/thou-shalt-not-modify-a-list-during-iteration/
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ kind: Pod
spec:
containers:
# ruleid: allow-privilege-escalation-no-securitycontext
- name: nginx
securityContext:
- securityContext:
allowPrivilegeEscalation: false
name: nginx
image: nginx
# ok: allow-privilege-escalation-no-securitycontext
- name: postgres
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rules:
containers:
...
- pattern-inside: |
- name: $CONTAINER
- $NAME: $CONTAINER
...
- pattern: |
image: ...
Expand All @@ -15,22 +15,25 @@ rules:
...
securityContext:
...
- focus-metavariable: $CONTAINER
- metavariable-regex:
metavariable: $NAME
regex: "name"
- focus-metavariable: $NAME
fix: |
$CONTAINER
securityContext:
allowPrivilegeEscalation: false
securityContext:
allowPrivilegeEscalation: false
$NAME
message: >-
In Kubernetes, each pod runs in its own isolated environment with its own
set of security policies. However, certain container images may contain
`setuid` or `setgid` binaries that could allow an attacker to perform
privilege escalation and gain access to sensitive resources. To mitigate
this risk, it's recommended to add a `securityContext` to the container in
the pod, with the parameter `allowPrivilegeEscalation` set to `false`.
This will prevent the container from running any privileged processes and
limit the impact of any potential attacks.
By adding a `securityContext` to your Kubernetes pod, you can help to
ensure that your containerized applications are more secure and less
In Kubernetes, each pod runs in its own isolated environment with its own
set of security policies. However, certain container images may contain
`setuid` or `setgid` binaries that could allow an attacker to perform
privilege escalation and gain access to sensitive resources. To mitigate
this risk, it's recommended to add a `securityContext` to the container in
the pod, with the parameter `allowPrivilegeEscalation` set to `false`.
This will prevent the container from running any privileged processes and
limit the impact of any potential attacks.
By adding a `securityContext` to your Kubernetes pod, you can help to
ensure that your containerized applications are more secure and less
vulnerable to privilege escalation attacks.
metadata:
cwe:
Expand Down
24 changes: 12 additions & 12 deletions yaml/kubernetes/security/allow-privilege-escalation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ rules:
- focus-metavariable: $SC
fix: |
securityContext:
allowPrivilegeEscalation: false #
allowPrivilegeEscalation: false #
message: >-
In Kubernetes, each pod runs in its own isolated environment with its own
set of security policies. However, certain container images may contain
`setuid` or `setgid` binaries that could allow an attacker to perform
privilege escalation and gain access to sensitive resources. To mitigate
this risk, it's recommended to add a `securityContext` to the container in
the pod, with the parameter `allowPrivilegeEscalation` set to `false`.
This will prevent the container from running any privileged processes and
limit the impact of any potential attacks.
By adding the `allowPrivilegeEscalation` parameter to your the
`securityContext`, you can help to
ensure that your containerized applications are more secure and less
In Kubernetes, each pod runs in its own isolated environment with its own
set of security policies. However, certain container images may contain
`setuid` or `setgid` binaries that could allow an attacker to perform
privilege escalation and gain access to sensitive resources. To mitigate
this risk, it's recommended to add a `securityContext` to the container in
the pod, with the parameter `allowPrivilegeEscalation` set to `false`.
This will prevent the container from running any privileged processes and
limit the impact of any potential attacks.
By adding the `allowPrivilegeEscalation` parameter to your the
`securityContext`, you can help to
ensure that your containerized applications are more secure and less
vulnerable to privilege escalation attacks.
metadata:
cwe:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ spec:
containers:
- name: nginx
# ruleid: run-as-non-root-container-level-missing-security-context
image: nginx
securityContext:
runAsNonRoot: true
image: nginx
- name: postgres
image: postgres
# this is okay because there already is a security context, requires different fix, different rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,34 @@ rules:
# Capture container image
- pattern: |
- name: $CONTAINER
image: $IMAGE
$IMAGE: $IMAGEVAL
...
# But missing securityContext
- pattern-not: |
- name: $CONTAINER
image: $IMAGE
image: $IMAGEVAL
...
securityContext:
...
- metavariable-regex:
metavariable: $IMAGE
regex: "image"
- focus-metavariable: $IMAGE
fix: |
securityContext:
runAsNonRoot: true
$IMAGE
securityContext:
runAsNonRoot: true
message: >-
When running containers in Kubernetes, it's important to ensure that they
are properly secured to prevent privilege escalation attacks.
One potential vulnerability is when a container is allowed to run
applications as the root user, which could allow an attacker to gain
access to sensitive resources. To mitigate this risk, it's recommended to
add a `securityContext` to the container, with the parameter `runAsNonRoot`
set to `true`. This will ensure that the container runs as a non-root user,
limiting the damage that could be caused by any potential attacks. By
adding a `securityContext` to the container in your Kubernetes pod, you can
help to ensure that your containerized applications are more secure and
When running containers in Kubernetes, it's important to ensure that they
are properly secured to prevent privilege escalation attacks.
One potential vulnerability is when a container is allowed to run
applications as the root user, which could allow an attacker to gain
access to sensitive resources. To mitigate this risk, it's recommended to
add a `securityContext` to the container, with the parameter `runAsNonRoot`
set to `true`. This will ensure that the container runs as a non-root user,
limiting the damage that could be caused by any potential attacks. By
adding a `securityContext` to the container in your Kubernetes pod, you can
help to ensure that your containerized applications are more secure and
less vulnerable to privilege escalation attacks.
metadata:
references:
Expand Down
22 changes: 11 additions & 11 deletions yaml/kubernetes/security/run-as-non-root-container-level.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ rules:
- focus-metavariable: $SC
fix: |
$SC:
runAsNonRoot: true #
runAsNonRoot: true #
message: >-
When running containers in Kubernetes, it's important to ensure that they
are properly secured to prevent privilege escalation attacks.
One potential vulnerability is when a container is allowed to run
applications as the root user, which could allow an attacker to gain
access to sensitive resources. To mitigate this risk, it's recommended to
add a `securityContext` to the container, with the parameter `runAsNonRoot`
set to `true`. This will ensure that the container runs as a non-root user,
limiting the damage that could be caused by any potential attacks. By
adding a `securityContext` to the container in your Kubernetes pod, you can
help to ensure that your containerized applications are more secure and
When running containers in Kubernetes, it's important to ensure that they
are properly secured to prevent privilege escalation attacks.
One potential vulnerability is when a container is allowed to run
applications as the root user, which could allow an attacker to gain
access to sensitive resources. To mitigate this risk, it's recommended to
add a `securityContext` to the container, with the parameter `runAsNonRoot`
set to `true`. This will ensure that the container runs as a non-root user,
limiting the damage that could be caused by any potential attacks. By
adding a `securityContext` to the container in your Kubernetes pod, you can
help to ensure that your containerized applications are more secure and
less vulnerable to privilege escalation attacks.
metadata:
references:
Expand Down
Loading

0 comments on commit 7d3b490

Please sign in to comment.