Skip to content

Conversation

erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented May 3, 2022

I did a LGTM run on ~1000 projects to evaluate js/actions/injection (see the internal backref).
I really liked the 3 results it found, so I think we should promote this query basically as is.

I've expanded the QHelp a bit, such that it's clear you can use this vulnerability to steal tokens.
(Those tokens have write access 😱).

I've put it as a high precision warning query, because I think this is good enough to run by default.

Commit-by-commit review is recommended.

Evaluation was uneventful.

@erik-krogh erik-krogh added WIP This is a work-in-progress, do not merge yet! Awaiting evaluation Do not merge yet, this PR is waiting for an evaluation to finish labels May 3, 2022
@erik-krogh erik-krogh removed Awaiting evaluation Do not merge yet, this PR is waiting for an evaluation to finish WIP This is a work-in-progress, do not merge yet! labels May 4, 2022
@erik-krogh erik-krogh marked this pull request as ready for review May 4, 2022 14:21
@erik-krogh erik-krogh requested a review from a team as a code owner May 4, 2022 14:21
*
* are equivalent.
*/
class MappingOrSequenceOrScalar extends YAMLNode {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in the standard library instead of in Actions.qll.
Actions can't be the only place where this liberal parsing is done.

* ```
* uses: actions/checkout@v2
* ```
* TODO: Does not currently handle local repository references, e.g. `.github/actions/action-name`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do something about this TODO, or track it elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class is only used in the experimenal js/actions/pull-request-target query, and in that query it's only used to check if there is a actions/checkout step.
I think we can just remove the TODO: part (and keep the rest of the comment), since it doesn't affect any current query.

Comment on lines 239 to 242
exists(string regexp | regexp = "([^/]+)/([^/@]+)@(.+)" |
repositoryOwner = this.getValue().regexpCapture(regexp, 1) and
repositoryName = this.getValue().regexpCapture(regexp, 2) and
version = this.getValue().regexpCapture(regexp, 3)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we bind these in the getters instead of the charpred such that we still have Uses instances for the local repository references that we do not yet parse correctly?

* Holds if `${{ e }}` is a GitHub Actions expression evaluated within this `run` command.
* See https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions.
*/
string getAReferencedExpression() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we avoid the TODO below if we rename the predicate to be more explicit about the limitations, i.e. getASimpleReferenceExpression?

In any case, the limitation should also have a positive and a negative example since the regexps are hard to parse mentally.

Comment on lines 18 to 19
The token has write access to the repository, and thus an attacker
can use it to modify the repository.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to update the QHelp such that it should be clear that the GITHUB_TOKEN only sometimes has write access.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 1 vulnerability.

Comment on lines +467 to +514
class YAMLMappingLikeNode extends YAMLNode {
YAMLMappingLikeNode() {
this instanceof YAMLMapping
or
this instanceof YAMLSequence
or
this instanceof YAMLScalar
}

/** Gets sub-name identified by `name`. */
YAMLNode getNode(string name) {
exists(YAMLMapping mapping |
mapping = this and
result = mapping.lookup(name)
)
or
exists(YAMLSequence sequence, YAMLNode node |
sequence = this and
sequence.getAChildNode() = node and
node.eval().toString() = name and
result = node
)
or
exists(YAMLScalar scalar |
scalar = this and
scalar.getValue() = name and
result = scalar
)
}

/** Gets the number of elements in this mapping or sequence. */
int getElementCount() {
exists(YAMLMapping mapping |
mapping = this and
result = mapping.getNumChild() / 2
)
or
exists(YAMLSequence sequence |
sequence = this and
result = sequence.getNumChild()
)
or
exists(YAMLScalar scalar |
scalar = this and
result = 1
)
}
}

Check warning

Code scanning / CodeQL

Acronyms should be PascalCase/camelCase.

Acronyms in YAMLMappingLikeNode should be PascalCase/camelCase
@esbena esbena added the ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. label May 9, 2022
esbena
esbena previously approved these changes May 9, 2022
guntrip
guntrip previously approved these changes May 12, 2022
Copy link
Contributor

@guntrip guntrip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing on behalf of @github/docs-content 👋 This looks great, I just made one small suggestion.

Co-authored-by: Steve Guntrip <12534592+stevecat@users.noreply.github.com>
@erik-krogh erik-krogh dismissed stale reviews from guntrip and esbena via fef4455 May 12, 2022 11:28
@erik-krogh erik-krogh requested a review from esbena May 12, 2022 11:29
@erik-krogh erik-krogh merged commit 4bef451 into github:main May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation JS ready-for-doc-review This PR requires and is ready for review from the GitHub docs team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants