Skip to content

Commit f99f5e8

Browse files
author
Dave Bartolomeo
committed
Merge remote-tracking branch 'origin/master' into dbartol/move-to-codeql
2 parents df3b304 + d0c761b commit f99f5e8

File tree

19 files changed

+832
-162
lines changed

19 files changed

+832
-162
lines changed

ql/lib/codeql/actions/Ast.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ class JsonReferenceExpression extends AstNode instanceof JsonReferenceExpression
379379
string getInnerExpression() { result = super.getInnerExpression() }
380380
}
381381

382+
class GitHubExpression extends SimpleReferenceExpression instanceof GitHubExpressionImpl { }
383+
382384
class SecretsExpression extends SimpleReferenceExpression instanceof SecretsExpressionImpl { }
383385

384386
class StepsExpression extends SimpleReferenceExpression instanceof StepsExpressionImpl {

ql/lib/codeql/actions/ast/internal/Ast.qll

Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,25 +1540,27 @@ string getAJsonReferenceAccessPath(string s, int offset) {
15401540
* A ${{}} expression accessing a sigcle context variable such as steps, needs, jobs, env, inputs, or matrix.
15411541
* https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
15421542
*/
1543-
abstract class SimpleReferenceExpressionImpl extends ExpressionImpl {
1544-
string expression;
1545-
1543+
class SimpleReferenceExpressionImpl extends ExpressionImpl {
15461544
SimpleReferenceExpressionImpl() {
1545+
exists(getASimpleReferenceExpression(this.getFullExpression(), _))
1546+
or
1547+
exists(getAJsonReferenceExpression(this.getFullExpression(), _))
1548+
}
1549+
1550+
override string getExpression() {
15471551
(
1548-
expression = getASimpleReferenceExpression(this.getFullExpression(), _)
1552+
result = getASimpleReferenceExpression(this.getFullExpression(), _)
15491553
or
15501554
exists(getAJsonReferenceExpression(this.getFullExpression(), _)) and
1551-
expression = this.getFullExpression()
1555+
result = this.getFullExpression()
15521556
)
15531557
}
15541558

1555-
override string getExpression() { result = expression }
1556-
15571559
abstract string getFieldName();
15581560

15591561
abstract AstNodeImpl getTarget();
15601562

1561-
override string toString() { result = expression }
1563+
override string toString() { result = this.getFullExpression() }
15621564
}
15631565

15641566
class JsonReferenceExpressionImpl extends ExpressionImpl {
@@ -1597,6 +1599,44 @@ private string inputsCtxRegex() {
15971599

15981600
private string secretsCtxRegex() { result = wrapRegexp("secrets\\.([A-Za-z0-9_-]+)") }
15991601

1602+
private string githubCtxRegex() {
1603+
result = wrapRegexp("github\\.([A-Za-z0-9'\"_\\[\\]\\*\\(\\)\\.\\-]+)")
1604+
}
1605+
1606+
/**
1607+
* Holds for an expression accesing the `github` context.
1608+
* e.g. `${{ github.head_ref }}`
1609+
*/
1610+
class GitHubExpressionImpl extends SimpleReferenceExpressionImpl {
1611+
GitHubExpressionImpl() {
1612+
exists(string expr |
1613+
(
1614+
exists(getAJsonReferenceExpression(this.getExpression(), _)) and
1615+
expr = normalizeExpr(this.getExpression()).regexpCapture("(?i)fromjson\\((.*)\\).*", 1)
1616+
or
1617+
exists(getASimpleReferenceExpression(this.getExpression(), _)) and
1618+
expr = normalizeExpr(this.getExpression())
1619+
) and
1620+
expr.regexpMatch(githubCtxRegex())
1621+
)
1622+
}
1623+
1624+
override string getFieldName() {
1625+
exists(string expr |
1626+
(
1627+
exists(getAJsonReferenceExpression(this.getExpression(), _)) and
1628+
expr = normalizeExpr(this.getExpression()).regexpCapture("(?i)fromjson\\((.*)\\).*", 1)
1629+
or
1630+
exists(getASimpleReferenceExpression(this.getExpression(), _)) and
1631+
expr = normalizeExpr(this.getExpression())
1632+
) and
1633+
result = expr.regexpCapture(githubCtxRegex(), 1)
1634+
)
1635+
}
1636+
1637+
override AstNodeImpl getTarget() { none() }
1638+
}
1639+
16001640
/**
16011641
* Holds for an expression accesing the `secrets` context.
16021642
* e.g. `${{ secrets.FOO }}`
@@ -1607,11 +1647,11 @@ class SecretsExpressionImpl extends SimpleReferenceExpressionImpl {
16071647
SecretsExpressionImpl() {
16081648
exists(string expr |
16091649
(
1610-
exists(getAJsonReferenceExpression(expression, _)) and
1611-
expr = normalizeExpr(expression).regexpCapture("(?i)fromjson\\((.*)\\).*", 1)
1650+
exists(getAJsonReferenceExpression(this.getExpression(), _)) and
1651+
expr = normalizeExpr(this.getExpression()).regexpCapture("(?i)fromjson\\((.*)\\).*", 1)
16121652
or
1613-
exists(getASimpleReferenceExpression(expression, _)) and
1614-
expr = normalizeExpr(expression)
1653+
exists(getASimpleReferenceExpression(this.getExpression(), _)) and
1654+
expr = normalizeExpr(this.getExpression())
16151655
) and
16161656
expr.regexpMatch(secretsCtxRegex()) and
16171657
fieldName = expr.regexpCapture(secretsCtxRegex(), 1)
@@ -1635,11 +1675,11 @@ class StepsExpressionImpl extends SimpleReferenceExpressionImpl {
16351675
StepsExpressionImpl() {
16361676
exists(string expr |
16371677
(
1638-
exists(getAJsonReferenceExpression(expression, _)) and
1639-
expr = normalizeExpr(expression).regexpCapture("(?i)(from|to)json\\((.*)\\).*", 2)
1678+
exists(getAJsonReferenceExpression(this.getExpression(), _)) and
1679+
expr = normalizeExpr(this.getExpression()).regexpCapture("(?i)(from|to)json\\((.*)\\).*", 2)
16401680
or
1641-
exists(getASimpleReferenceExpression(expression, _)) and
1642-
expr = normalizeExpr(expression)
1681+
exists(getASimpleReferenceExpression(this.getExpression(), _)) and
1682+
expr = normalizeExpr(this.getExpression())
16431683
) and
16441684
expr.regexpMatch(stepsCtxRegex()) and
16451685
stepId = expr.regexpCapture(stepsCtxRegex(), 1) and
@@ -1676,11 +1716,11 @@ class NeedsExpressionImpl extends SimpleReferenceExpressionImpl {
16761716
NeedsExpressionImpl() {
16771717
exists(string expr |
16781718
(
1679-
exists(getAJsonReferenceExpression(expression, _)) and
1680-
expr = normalizeExpr(expression).regexpCapture("(?i)(from|to)json\\((.*)\\).*", 2)
1719+
exists(getAJsonReferenceExpression(this.getExpression(), _)) and
1720+
expr = normalizeExpr(this.getExpression()).regexpCapture("(?i)(from|to)json\\((.*)\\).*", 2)
16811721
or
1682-
exists(getASimpleReferenceExpression(expression, _)) and
1683-
expr = normalizeExpr(expression)
1722+
exists(getASimpleReferenceExpression(this.getExpression(), _)) and
1723+
expr = normalizeExpr(this.getExpression())
16841724
) and
16851725
expr.regexpMatch(needsCtxRegex()) and
16861726
fieldName = expr.regexpCapture(needsCtxRegex(), 2) and
@@ -1720,11 +1760,11 @@ class JobsExpressionImpl extends SimpleReferenceExpressionImpl {
17201760
JobsExpressionImpl() {
17211761
exists(string expr |
17221762
(
1723-
exists(getAJsonReferenceExpression(expression, _)) and
1724-
expr = normalizeExpr(expression).regexpCapture("(?i)(from|to)json\\((.*)\\).*", 2)
1763+
exists(getAJsonReferenceExpression(this.getExpression(), _)) and
1764+
expr = normalizeExpr(this.getExpression()).regexpCapture("(?i)(from|to)json\\((.*)\\).*", 2)
17251765
or
1726-
exists(getASimpleReferenceExpression(expression, _)) and
1727-
expr = normalizeExpr(expression)
1766+
exists(getASimpleReferenceExpression(this.getExpression(), _)) and
1767+
expr = normalizeExpr(this.getExpression())
17281768
) and
17291769
expr.regexpMatch(jobsCtxRegex()) and
17301770
jobId = expr.regexpCapture(jobsCtxRegex(), 1) and
@@ -1752,8 +1792,8 @@ class InputsExpressionImpl extends SimpleReferenceExpressionImpl {
17521792
string fieldName;
17531793

17541794
InputsExpressionImpl() {
1755-
normalizeExpr(expression).regexpMatch(inputsCtxRegex()) and
1756-
fieldName = normalizeExpr(expression).regexpCapture(inputsCtxRegex(), 1)
1795+
normalizeExpr(this.getExpression()).regexpMatch(inputsCtxRegex()) and
1796+
fieldName = normalizeExpr(this.getExpression()).regexpCapture(inputsCtxRegex(), 1)
17571797
}
17581798

17591799
override string getFieldName() { result = fieldName }
@@ -1779,11 +1819,11 @@ class EnvExpressionImpl extends SimpleReferenceExpressionImpl {
17791819
EnvExpressionImpl() {
17801820
exists(string expr |
17811821
(
1782-
exists(getAJsonReferenceExpression(expression, _)) and
1783-
expr = normalizeExpr(expression).regexpCapture("(?i)(from|to)json\\((.*)\\).*", 2)
1822+
exists(getAJsonReferenceExpression(this.getExpression(), _)) and
1823+
expr = normalizeExpr(this.getExpression()).regexpCapture("(?i)(from|to)json\\((.*)\\).*", 2)
17841824
or
1785-
exists(getASimpleReferenceExpression(expression, _)) and
1786-
expr = normalizeExpr(expression)
1825+
exists(getASimpleReferenceExpression(this.getExpression(), _)) and
1826+
expr = normalizeExpr(this.getExpression())
17871827
) and
17881828
expr.regexpMatch(envCtxRegex()) and
17891829
fieldName = expr.regexpCapture(envCtxRegex(), 1)
@@ -1814,11 +1854,11 @@ class MatrixExpressionImpl extends SimpleReferenceExpressionImpl {
18141854
MatrixExpressionImpl() {
18151855
exists(string expr |
18161856
(
1817-
exists(getAJsonReferenceExpression(expression, _)) and
1818-
expr = normalizeExpr(expression).regexpCapture("(?i)(from|to)json\\((.*)\\).*", 2)
1857+
exists(getAJsonReferenceExpression(this.getExpression(), _)) and
1858+
expr = normalizeExpr(this.getExpression()).regexpCapture("(?i)(from|to)json\\((.*)\\).*", 2)
18191859
or
1820-
exists(getASimpleReferenceExpression(expression, _)) and
1821-
expr = normalizeExpr(expression)
1860+
exists(getASimpleReferenceExpression(this.getExpression(), _)) and
1861+
expr = normalizeExpr(this.getExpression())
18221862
) and
18231863
expr.regexpMatch(matrixCtxRegex()) and
18241864
fieldAccess = expr.regexpCapture(matrixCtxRegex(), 1)

0 commit comments

Comments
 (0)