Skip to content

Commit 313acfc

Browse files
author
Alvaro Muñoz
committed
Add externally triggereable data model and predicates
1 parent d3bff87 commit 313acfc

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

ql/lib/codeql/actions/Ast.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ abstract class Job extends AstNode instanceof JobImpl {
348348

349349
predicate isPrivileged() { super.isPrivileged() }
350350

351+
predicate isExternallyTriggerable() { super.isExternallyTriggerable() }
352+
351353
string getARunsOnLabel() { result = super.getARunsOnLabel() }
352354
}
353355

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,11 @@ class JobImpl extends AstNodeImpl, TJobNode {
703703
/** Gets the strategy for this job. */
704704
StrategyImpl getStrategy() { result.getNode() = n.lookup("strategy") }
705705

706+
/** Holds if the job can be triggered by an external actor. */
707+
predicate isExternallyTriggerable() {
708+
externallyTriggerableEventsDataModel(this.getATriggerEvent().getName())
709+
}
710+
706711
/** Holds if the job is privileged. */
707712
predicate isPrivileged() {
708713
// the job has privileged runtime permissions

ql/lib/codeql/actions/dataflow/ExternalFlow.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ predicate contextTriggerDataModel(string trigger, string context_prefix) {
3838
Extensions::contextTriggerDataModel(trigger, context_prefix)
3939
}
4040

41+
/**
42+
* MaD models for externally triggerable events
43+
* Fields:
44+
* - event: Event name
45+
*/
46+
predicate externallyTriggerableEventsDataModel(string event) {
47+
Extensions::externallyTriggerableEventsDataModel(event)
48+
}
49+
4150
/**
4251
* MaD sources
4352
* Fields:

ql/lib/codeql/actions/dataflow/internal/ExternalFlowExtensions.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ extensible predicate workflowDataModel(
3636
extensible predicate repositoryDataModel(string visibility, string default_branch_name);
3737

3838
/**
39-
* Holds if context/trigger mapping exists for the given parameters.
39+
* Holds if a context expression starting with context_prefix is available for a given trigger.
4040
*/
4141
extensible predicate contextTriggerDataModel(string trigger, string context_prefix);
42+
43+
/**
44+
* Holds if a given trigger event can be fired by an external actor.
45+
*/
46+
extensible predicate externallyTriggerableEventsDataModel(string event);

ql/lib/ext/workflow-models/workflow-models.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ extensions:
1111
pack: githubsecuritylab/actions-all
1212
extensible: contextTriggerDataModel
1313
data:
14-
# This predicate maps triggering events with the github event context available for that event
1514
- ["commit_comment", "github.event.comment"]
1615
- ["discussion", "github.event.discussion"]
1716
- ["discussion_comment", "github.event.comment"]
@@ -55,3 +54,19 @@ extensions:
5554
- ["workflow_call", "github.event.review"]
5655
- ["workflow_call", "github.event.workflow"]
5756
- ["workflow_call", "github.event.workflow_run"]
57+
- addsTo:
58+
pack: githubsecuritylab/actions-all
59+
extensible: externallyTriggerableEventsDataModel
60+
data:
61+
- ["discussion"]
62+
- ["discussion_comment"]
63+
- ["fork"]
64+
- ["issue_comment"]
65+
- ["issues"]
66+
- ["pull_request"]
67+
- ["pull_request_comment"]
68+
- ["pull_request_review"]
69+
- ["pull_request_review_comment"]
70+
- ["pull_request_target"]
71+
- ["workflow_run"] # depending on trigger workflow
72+
- ["workflow_call"] # depending on caller

0 commit comments

Comments
 (0)