1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use github_actions_models::common::{EnvValue, RepositoryUses, Uses, expr::LoE};
use indexmap::IndexMap;
use subfeature::Subfeature;
use crate::{
audit::{Audit, AuditError, AuditLoadError, audit_meta},
config::Config,
finding::{Confidence, Finding, Persona, Severity},
models::{
StepBodyCommon, StepCommon, action::CompositeStep, uses::RepositoryUsesExt, workflow::Step,
},
state::AuditState,
utils::ExtractedExpr,
};
pub(crate) struct GitHubApp;
audit_meta!(
GitHubApp,
"github-app",
"dangerous use of GitHub App tokens"
);
impl GitHubApp {
fn process_step<'doc>(
&self,
step: &impl StepCommon<'doc>,
) -> Result<Vec<Finding<'doc>>, AuditError> {
let StepBodyCommon::Uses {
uses: Uses::Repository(uses),
with,
} = step.body()
else {
return Ok(vec![]);
};
let findings = if uses.matches("actions/create-github-app-token") {
self.process_create_github_app_token(step, uses, with)?
} else {
// TODO: Maybe check tibdex/github-app-token as well?
// TODO: Flag getsentry/action-github-app-token as well? It doesn't support any of
// the scoping that create-github-app-token does, so we could perhaps
// nudge users away from it.
// TODO: Flag wow-actions/use-app-token for similar reasons.
vec![]
};
Ok(findings)
}
fn process_create_github_app_token<'doc>(
&self,
step: &impl StepCommon<'doc>,
uses: &'doc RepositoryUses,
with: &'doc LoE<IndexMap<String, EnvValue>>,
) -> Result<Vec<Finding<'doc>>, AuditError> {
let mut findings = vec![];
let LoE::Literal(with) = with else {
// The user did `with: ${{ expr }}`, which we can't analyze at the moment.
// This gets flagged separately in `obfuscation`.
tracing::debug!("skipping analysis of non-literal `with` for create-github-app-token");
return Ok(findings);
};
// `skip-token-revoke: true` means the user has explicitly disabled
// the action's default token revocation behavior.
if let Some(skip_token_revoke) = with.get("skip-token-revoke") {
match skip_token_revoke.actions_toolkit_bool() {
Some(true) => findings.push(
Self::finding()
.confidence(Confidence::High)
.severity(Severity::High)
.persona(Persona::Regular)
.add_location(
step.location()
.with_keys(["uses".into()])
.subfeature(Subfeature::new(0, uses.raw()))
.annotated("app token requested here"),
)
.add_location(
step.location()
.with_keys(["with".into(), "skip-token-revoke".into()])
.annotated("token revocation disabled here")
.primary(),
)
.build(step)?,
),
Some(false) => (),
None => {
// The user might have done `skip-token-revoke: ${{ expr }}`.
if let EnvValue::String(skip_token_revoke) = skip_token_revoke
&& ExtractedExpr::from_fenced(skip_token_revoke).is_some()
{
findings.push(
Self::finding()
.confidence(Confidence::Low)
.severity(Severity::High)
.persona(Persona::Regular)
.add_location(
step.location()
.with_keys(["uses".into()])
.subfeature(Subfeature::new(0, uses.raw()))
.annotated("app token requested here"),
)
.add_location(
step.location()
.with_keys(["with".into(), "skip-token-revoke".into()])
.annotated("token revocation conditionally disabled here")
.primary(),
)
.build(step)?,
);
}
}
}
}
// `owner: ...` without `repositories: ...` grants the app token access to all
// repositories in the owner's account, which is likely more access than the
// user intended.
if with.contains_key("owner") && !with.contains_key("repositories") {
findings.push(
Self::finding()
.confidence(Confidence::High)
.severity(Severity::High)
.persona(Persona::Regular)
.add_location(
step.location()
.with_keys(["uses".into()])
.subfeature(Subfeature::new(0, uses.raw()))
.annotated("app token requested here"),
)
.add_location(
step.location()
.with_keys(["with".into(), "owner".into()])
.annotated("token granted access to all repositories for this owner's app installation")
.primary(),
)
.tip("use `repositories: 'repo1,repo2'` to scope the token to specific repositories")
.build(step)?,
);
}
// If the user doesn't specify at least one `permission-<name>` input,
// then the action defaults to granting the token all installation permissions,
// which can be very broad.
if !with.keys().any(|k| k.starts_with("permission-")) {
findings.push(
Self::finding()
.confidence(Confidence::High)
.severity(Severity::High)
.persona(Persona::Regular)
.add_location(
step.location()
.with_keys(["uses".into()])
.subfeature(Subfeature::new(0, uses.raw()))
.annotated("app token inherits blanket installation permissions"),
)
.tip("specify at least one `permission-<name>` input to limit the token's permissions")
.build(step)?,
);
}
Ok(findings)
}
}
#[async_trait::async_trait]
impl Audit for GitHubApp {
fn new(_state: &AuditState) -> Result<Self, AuditLoadError>
where
Self: Sized,
{
Ok(Self)
}
async fn audit_step<'doc>(
&self,
step: &Step<'doc>,
_config: &Config,
) -> Result<Vec<Finding<'doc>>, AuditError> {
self.process_step(step)
}
async fn audit_composite_step<'doc>(
&self,
step: &CompositeStep<'doc>,
_config: &Config,
) -> Result<Vec<Finding<'doc>>, AuditError> {
self.process_step(step)
}
}