Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion actions/ql/lib/codeql/actions/PowerShell.qll
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class PowerShellScript extends ShellScript {
PowerShellScript() {
exists(Run run |
this = run.getScript() and
run.getShell().matches("pwsh%")
run.getShell().startsWith("pwsh")
)
}

Expand Down
24 changes: 12 additions & 12 deletions actions/ql/lib/codeql/actions/ast/internal/Ast.qll
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ class ShellScriptImpl extends ScalarValueImpl {
abstract string getCommand(int i);

string getACommand() {
if this.getEnclosingRun().getShell().matches("bash%")
if this.getEnclosingRun().getShell().startsWith("bash")
then result = this.(BashShellScript).getACommand()
else
if this.getEnclosingRun().getShell().matches("pwsh%")
if this.getEnclosingRun().getShell().startsWith("pwsh")
then result = this.(PowerShellScript).getACommand()
else result = "NOT IMPLEMENTED"
}
Expand Down Expand Up @@ -436,7 +436,7 @@ class CompositeActionImpl extends AstNodeImpl, TCompositeAction {

private predicate hasExplicitWritePermission() {
// a calling job has an explicit write permission
this.getACallerJob().getPermissions().getAPermission().matches("%write")
this.getACallerJob().getPermissions().getAPermission().endsWith("write")
}

/** Holds if the action is privileged. */
Expand Down Expand Up @@ -981,12 +981,12 @@ class JobImpl extends AstNodeImpl, TJobNode {
private predicate hasExplicitReadPermission() {
// the job has not an explicit write permission
exists(this.getPermissions().getAPermission()) and
not this.getPermissions().getAPermission().matches("%write")
not this.getPermissions().getAPermission().endsWith("write")
}

private predicate hasExplicitWritePermission() {
// the job has an explicit write permission
this.getPermissions().getAPermission().matches("%write")
this.getPermissions().getAPermission().endsWith("write")
}

private predicate hasImplicitNonePermission() {
Expand All @@ -1010,7 +1010,7 @@ class JobImpl extends AstNodeImpl, TJobNode {
// the job has not an explicit write permission
not exists(this.getPermissions()) and
exists(this.getEnclosingWorkflow().getPermissions().getAPermission()) and
not this.getEnclosingWorkflow().getPermissions().getAPermission().matches("%write")
not this.getEnclosingWorkflow().getPermissions().getAPermission().endsWith("write")
or
not exists(this.getPermissions()) and
not exists(this.getEnclosingWorkflow().getPermissions()) and
Expand All @@ -1019,13 +1019,13 @@ class JobImpl extends AstNodeImpl, TJobNode {
.getACaller()
.getPermissions()
.getAPermission()
.matches("%read")
.endsWith("read")
}

private predicate hasImplicitWritePermission() {
// the job has an explicit write permission
not exists(this.getPermissions()) and
this.getEnclosingWorkflow().getPermissions().getAPermission().matches("%write")
this.getEnclosingWorkflow().getPermissions().getAPermission().endsWith("write")
or
not exists(this.getPermissions()) and
not exists(this.getEnclosingWorkflow().getPermissions()) and
Expand All @@ -1034,7 +1034,7 @@ class JobImpl extends AstNodeImpl, TJobNode {
.getACaller()
.getPermissions()
.getAPermission()
.matches("%write")
.endsWith("write")
}

private predicate hasRuntimeData() {
Expand All @@ -1054,7 +1054,7 @@ class JobImpl extends AstNodeImpl, TJobNode {
// We cannot trust the permissions for pull_request events since they depend on the
// provenance of the head branch (local vs fork)
not trigger.trim() = "pull_request" and
perms.toLowerCase().matches("%write%")
perms.toLowerCase().contains("write")
)
}

Expand Down Expand Up @@ -1400,7 +1400,7 @@ class ExternalJobImpl extends JobImpl, UsesImpl {
ExternalJobImpl() { n.lookup("uses") = u }

override string getCallee() {
if u.getValue().matches("./%")
if u.getValue().startsWith("./")
then result = u.getValue().regexpCapture(pathUsesParser(), 1)
else
result =
Expand Down Expand Up @@ -1457,7 +1457,7 @@ class RunImpl extends StepImpl {
if this.getEnclosingJob().getARunsOnLabel().matches(["ubuntu%", "macos%"])
then result = "bash"
else
if this.getEnclosingJob().getARunsOnLabel().matches("windows%")
if this.getEnclosingJob().getARunsOnLabel().startsWith("windows")
then result = "pwsh"
else result = "bash"
}
Expand Down
2 changes: 1 addition & 1 deletion actions/ql/lib/codeql/actions/config/Config.qll
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ predicate immutableActionsDataModel(string action) { Extensions::immutableAction
*/
predicate trustedActionsOwnerDataModel(string owner) {
Extensions::trustedActionsOwnerDataModel(owner) and
not owner.matches("!%") and
not owner.startsWith("!") and
not Extensions::trustedActionsOwnerDataModel("!" + owner)
}

Expand Down
12 changes: 6 additions & 6 deletions actions/ql/lib/codeql/actions/dataflow/ExternalFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ predicate madSource(DataFlow::Node source, string kind, string fieldName) {
else uses.getVersion() = version.trim()
) and
(
if fieldName.trim().matches("env.%")
if fieldName.trim().startsWith("env.")
then source.asExpr() = uses.getInScopeEnvVarExpr(fieldName.trim().replaceAll("env.", ""))
else (
fieldName.trim().matches("output.%") and
fieldName.trim().startsWith("output.") and
source.asExpr() = uses
)
)
Expand All @@ -87,10 +87,10 @@ predicate madStoreStep(DataFlow::Node pred, DataFlow::Node succ, DataFlow::Conte
) and
// pred provenance
(
input.trim().matches("env.%") and
input.trim().startsWith("env.") and
pred.asExpr() = uses.getInScopeEnvVarExpr(input.trim().replaceAll("env.", ""))
or
input.trim().matches("input.%") and
input.trim().startsWith("input.") and
pred.asExpr() = uses.getArgumentExpr(input.trim().replaceAll("input.", ""))
or
input.trim() = "artifact" and
Expand Down Expand Up @@ -118,10 +118,10 @@ predicate madSink(DataFlow::Node sink, string kind) {
) and
// pred provenance
(
input.trim().matches("env.%") and
input.trim().startsWith("env.") and
sink.asExpr() = uses.getInScopeEnvVarExpr(input.trim().replaceAll("env.", ""))
or
input.trim().matches("input.%") and
input.trim().startsWith("input.") and
sink.asExpr() = uses.getArgumentExpr(input.trim().replaceAll("input.", ""))
or
input.trim() = "artifact" and
Expand Down
12 changes: 6 additions & 6 deletions actions/ql/lib/codeql/actions/dataflow/FlowSources.qll
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class GitHubEventPathSource extends RemoteFlowSource, CommandSource {
GitHubEventPathSource() {
this.asExpr() = run.getScript() and
run.getScript().getACommand() = cmd and
cmd.matches("jq%") and
cmd.startsWith("jq") and
cmd.matches("%GITHUB_EVENT_PATH%") and
exists(string regexp, string access_path |
untrustedEventPropertiesDataModel(regexp, flag) and
Expand Down Expand Up @@ -371,11 +371,11 @@ class OctokitRequestActionSource extends RemoteFlowSource {
route = u.getArgument("route").trim() and
route.indexOf("GET") = 0 and
(
route.matches("%/commits%") or
route.matches("%/comments%") or
route.matches("%/pulls%") or
route.matches("%/issues%") or
route.matches("%/users%") or
route.contains("/commits") or
route.contains("/comments") or
route.contains("/pulls") or
route.contains("/issues") or
route.contains("/users") or
route.matches("%github.event.issue.pull_request.url%")
) and
this.asExpr() = u
Expand Down
4 changes: 2 additions & 2 deletions actions/ql/lib/codeql/actions/dataflow/TaintSteps.qll
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ predicate zenteredIssueFormBodyParserSource(DataFlow::Node pred, DataFlow::Node
o.getFieldName() = "data"
or
o instanceof JsonReferenceExpression and
o.(JsonReferenceExpression).getInnerExpression().matches("%.data")
o.(JsonReferenceExpression).getInnerExpression().endsWith(".data")
) and
succ.asExpr() = o
)
Expand All @@ -124,7 +124,7 @@ predicate octokitRequestActionTaintStep(DataFlow::Node pred, DataFlow::Node succ
o.getFieldName() = "data"
or
o instanceof JsonReferenceExpression and
o.(JsonReferenceExpression).getInnerExpression().matches("%.data") and
o.(JsonReferenceExpression).getInnerExpression().endsWith(".data") and
o.(JsonReferenceExpression)
.getAccessPath()
.matches([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ class ActionsGitHubScriptDownloadStep extends UntrustedArtifactDownloadStep, Use
this.getCallee() = "actions/github-script" and
exists(string script |
this.getArgument("script") = script and
script.matches("%listWorkflowRunArtifacts(%") and
script.matches("%downloadArtifact(%") and
script.matches("%writeFileSync(%") and
script.contains("listWorkflowRunArtifacts(") and
script.contains("downloadArtifact(") and
script.contains("writeFileSync(") and
// Filter out artifacts that were created by pull-request.
not script.matches("%exclude_pull_requests: true%")
)
Expand Down Expand Up @@ -265,7 +265,7 @@ class ArtifactPoisoningSink extends DataFlow::Node {
exists(PoisonableStep poisonable |
download.getAFollowingStep() = poisonable and
// excluding artifacts downloaded to the temporary directory
not download.getPath().regexpMatch("^/tmp.*") and
not download.getPath().startsWith("/tmp") and
not download.getPath().regexpMatch("^\\$\\{\\{\\s*runner\\.temp\\s*}}.*") and
not download.getPath().regexpMatch("^\\$RUNNER_TEMP.*")
|
Expand Down
6 changes: 3 additions & 3 deletions actions/ql/lib/codeql/actions/security/ControlChecks.qll
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class ActorIfCheck extends ActorCheck instanceof If {
normalizeExpr(this.getCondition())
.regexpFind(["\\bgithub\\.actor\\b", "\\bgithub\\.triggering_actor\\b",], _, _)
) and
not normalizeExpr(this.getCondition()).matches("%[bot]%")
not normalizeExpr(this.getCondition()).contains("[bot]")
}
}

Expand Down Expand Up @@ -462,7 +462,7 @@ class AssociationActionCheck extends AssociationCheck instanceof UsesStep {
)
or
this.getCallee() = "actions/github-script" and
this.getArgument("script").splitAt("\n").matches("%getMembershipForUserInOrg%")
this.getArgument("script").splitAt("\n").contains("getMembershipForUserInOrg")
or
this.getCallee() = "octokit/request-action" and
this.getArgument("route").regexpMatch("GET.*(memberships).*")
Expand Down Expand Up @@ -495,7 +495,7 @@ class PermissionActionCheck extends PermissionCheck instanceof UsesStep {
)
or
this.getCallee() = "actions/github-script" and
this.getArgument("script").splitAt("\n").matches("%getCollaboratorPermissionLevel%")
this.getArgument("script").splitAt("\n").contains("getCollaboratorPermissionLevel")
or
this.getCallee() = "octokit/request-action" and
this.getArgument("route").regexpMatch("GET.*(collaborators|permission).*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private module OutputClobberingConfig implements DataFlow::ConfigSig {
succ.asExpr() = run.getScript() and
(
exists(run.getScript().getAFileReadCommand()) or
run.getScript().getAStmt().matches("%::set-output %")
run.getScript().getAStmt().contains("::set-output ")
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class LocalScriptExecutionRunStep extends PoisonableStep, Run {
}

class LocalActionUsesStep extends PoisonableStep, UsesStep {
LocalActionUsesStep() { this.getCallee().matches("./%") }
LocalActionUsesStep() { this.getCallee().startsWith("./") }

string getPath() { result = normalizePath(this.getCallee()) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class SimplePRHeadCheckoutStep extends Step {
this = uses and
uses.getCallee() = "actions/checkout" and
exists(uses.getArgument("ref")) and
not uses.getArgument("ref").matches("%base%") and
not uses.getArgument("ref").contains("base") and
uses.getATriggerEvent().getName() = checkoutTriggers()
)
or
Expand Down
2 changes: 1 addition & 1 deletion actions/ql/lib/codeql/files/FileSystem.qll
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ abstract class Container extends @container {
absPath = pref and result = ""
or
absPath = pref.regexpReplaceAll("/$", "") + "/" + result and
not result.matches("/%")
not result.startsWith("/")
)
}

Expand Down
6 changes: 3 additions & 3 deletions actions/ql/src/Security/CWE-312/ExcessiveSecretsExposure.ql
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import codeql.actions.ast.internal.Ast

from Expression expr
where
getAToJsonReferenceExpression(expr.getExpression(), _).matches("secrets%")
getAToJsonReferenceExpression(expr.getExpression(), _).startsWith("secrets")
or
expr.getExpression().matches("secrets[%") and
expr.getExpression().startsWith("secrets[") and
not expr.getExpression().matches("secrets[\"%") and
not expr.getExpression().matches("secrets['%")
not expr.getExpression().startsWith("secrets['")
select expr, "All organization and repository secrets are passed to the workflow runner in $@",
expr, expr.getExpression()
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import codeql.actions.security.ControlChecks

from ControlCheck i
where
i.(If).getCondition().matches("%${{%") and
i.(If).getCondition().contains("${{") and
(
not i.(If).getCondition().matches("${{%") or
not i.(If).getCondition().matches("%}}")
not i.(If).getCondition().startsWith("${{") or
not i.(If).getCondition().endsWith("}}")
)
or
count(i.(If).getCondition().splitAt("${{")) > 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ from If i
where
not i instanceof ControlCheck and
(
i.getCondition().matches("%${{%") and
i.getCondition().contains("${{") and
(
not i.getCondition().matches("${{%") or
not i.getCondition().matches("%}}")
not i.getCondition().startsWith("${{") or
not i.getCondition().endsWith("}}")
)
or
count(i.getCondition().splitAt("${{")) > 2
Expand Down
2 changes: 1 addition & 1 deletion actions/ql/src/Security/CWE-829/UnpinnedActionsTag.ql
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private predicate isContainerImage(string nwo) { nwo.regexpMatch("^docker://.+")
// resolved at the commit the calling workflow is running. Like `./` local (self workspace)
// references, it is inherently pinned and can never be an unpinned-tag finding, so we never flag it.
bindingset[nwo]
private predicate isSelfRepository(string nwo) { nwo.matches("$/%") }
private predicate isSelfRepository(string nwo) { nwo.startsWith("$/") }

private predicate hasUsesContainerName(Uses uses, string name) {
exists(Workflow workflow |
Expand Down
2 changes: 1 addition & 1 deletion cpp/ql/examples/snippets/todocomment.ql
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
import cpp

from Comment c
where c.getContents().matches("%TODO%")
where c.getContents().contains("TODO")
select c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
(
(result.length() <= 4 and result = "DESX")
implies
(f.getName().toUpperCase().matches("%DESX%") or f.getName().toUpperCase().matches("%DES_X%"))
(f.getName().toUpperCase().contains("DESX") or f.getName().toUpperCase().matches("%DES_X%"))
) and
// (result.length() <= 3 implies (not f.getName().toUpperCase().regexpMatch(".*" + result + "[a-zA-Z0-9].*|.*[a-zA-Z0-9]" + result + ".*")))
// and
Expand All @@ -90,7 +90,7 @@
implies
not f.getName().toUpperCase().regexpMatch(".*DES[a-zA-Z0-9].*|.*[a-zA-Z0-9]DES.*")
) and
// ((result.matches("%DES%")) implies not exists(string s | s in ["DESCRIBE", "DESTROY", "DESCRIPTION", "DESCRIPTOR", "NODES"] |
// ((result.contains("DES")) implies not exists(string s | s in ["DESCRIBE", "DESTROY", "DESCRIPTION", "DESCRIPTOR", "NODES"] |
// f.getName().toUpperCase().matches("%" + s + "%"))) and
// SEED specific false positives
(
Expand All @@ -106,16 +106,16 @@
)
) and
// ARIA specific false positives
(result.matches("ARIA") implies not f.getName().toUpperCase().matches("%VARIANT%")) and
(result.matches("ARIA") implies not f.getName().toUpperCase().contains("VARIANT")) and
// CTR false positives
(result.matches("CTR") implies not f.getName().toUpperCase().matches("%CTRL%")) and
(result.matches("CTR") implies not f.getName().toUpperCase().contains("CTRL")) and
// ES false positives (e.g., ES256 from AES256)
(result.matches("ES%") implies not f.getName().toUpperCase().matches("%AES%")) and
(result.startsWith("ES") implies not f.getName().toUpperCase().contains("AES")) and
// RSA false positives
(result.matches("RSA") implies not f.getName().toUpperCase().matches("%UNIVERSAL%")) and
(result.matches("RSA") implies not f.getName().toUpperCase().contains("UNIVERSAL")) and
//rsaz functions deemed to be too low level, and can be ignored
not f.getLocation().getFile().getBaseName().matches("rsaz_exp.c") and
// General False positives
// Functions that 'get' do not set an algorithm, and therefore are considered ignorable
not f.getName().toLowerCase().matches("%get%")
not f.getName().toLowerCase().contains("get")
}
Loading
Loading