Sitelet https://web.archive.org/web/20211219030300/https://github.com/github/codeql/pull/7419
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby: Add Module#const_get as a code execution #7419

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

@hmac
Copy link
Contributor

@hmac hmac commented Dec 16, 2021

Module#const_get takes a single string argument and interprets it as the
name of a constant. It then looks up the constant and returns its value.

Object.const_get("Math::PI")
# => 3.141592653589793

By itself, this method is not as dangerous as e.g. eval, but if the
value returned is a class that is then instantiated, this can allow an
attacker to instantiate arbitrary Ruby classes.

As a result, I think it's safe to say that any remote input flowing into
this call is a potential vulnerability. A real-world example of this is
GHSA-52p9-v744-mwjj.

Module#const_get takes a single string argument and interprets it as the
name of a constant. It then looks up the constant and returns its value.

    Object.const_get("Math::PI")
    # => 3.141592653589793

By itself, this method is not as dangerous as e.g. eval, but if the
value returned is a class that is then instantiated, this can allow an
attacker to instantiate arbitrary Ruby classes.

As a result, I think it's safe to say that any remote input flowing into
this call is a potential vulnerability. A real-world example of this is
GHSA-52p9-v744-mwjj.
@github-actions github-actions bot added the Ruby label Dec 16, 2021
@hmac hmac marked this pull request as ready for review Dec 16, 2021
@hmac hmac requested a review from as a code owner Dec 16, 2021
*/
class ModuleConstGetCallCodeExecution extends CodeExecution::Range, DataFlow::CallNode {
ModuleConstGetCallCodeExecution() {
this.asExpr().getExpr().(UnknownMethodCall).getMethodName() = "const_get"
Copy link
Contributor

@nickrolfe nickrolfe Dec 17, 2021

Choose a reason for hiding this comment

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

I'm a little unsure about casting to UnknownMethodCall. Is the idea that all bets are off if the project redefines Module#const_get?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants