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

User can escape the sandbox language #29

Closed
jcubic opened this issue Dec 24, 2021 · 4 comments
Closed

User can escape the sandbox language #29

jcubic opened this issue Dec 24, 2021 · 4 comments

Comments

@jcubic
Copy link
Owner

jcubic commented Dec 24, 2021

echo "${await gaiman.ask('? ')}"

This is valid and it's interpreted by gaiman, and it's executed. This is potential XSS.

Reported upstream estools/escodegen#448

@jcubic jcubic changed the title User can escape the sandbox langauge User can escape the sandbox language Dec 24, 2021
@jcubic
Copy link
Owner Author

jcubic commented Dec 25, 2021

Another example is using constructor (after adding methods):

x = location.constructor.constructor("alert('x')")
x()

@jcubic
Copy link
Owner Author

jcubic commented Dec 25, 2021

Here is hacked eval function:

def eval(str)
    let fn = location.constructor.constructor("return $str")
    return fn()
end

let factorial = eval("(function(n) {
    return Array.from({length: n}, (_, i) => i + 1).reduce((a,b) => a * b, 1);
})")

echo factorial(10)

@jcubic
Copy link
Owner Author

jcubic commented Dec 25, 2021

I think that it will be not possible to protect the language, constructor can't be blacklisted because user can get the property dynamically:

def eval(str)
    let constructor = location["constructor"]["constructor"]
    let fn = constructor("return $str")
    return fn()
end

I think that if someone wants to hack the language it's ok, but with the original issue of the template literal, the user can inject the code into the developer game. Which can be a problem and security.

jcubic added a commit that referenced this issue Feb 14, 2022
@jcubic jcubic closed this as completed Feb 14, 2022
@jcubic
Copy link
Owner Author

jcubic commented Feb 14, 2022

Actually previous example will not work, because Gaiman don't support mutlline strings:

This code that currently works:

let code = <<<CODE
(function(n) {
   return Array.from({length: n}, (_, i) => i + 1).reduce((a,b) => a * b, 1);
})
CODE

let factorial = eval(code)

echo factorial(10)

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

No branches or pull requests

1 participant