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

Prevent certain Lua modules/functions from loading #663

Merged
merged 5 commits into from
Nov 21, 2022

Conversation

program--
Copy link
Contributor

This PR resolves #630.

Changes:

  • Modified lua.NewState() call to open only the following modules:
    • base*
    • table
    • math
    • string
    • os*

    * Only opens base.tonumber(), base.tostring(), os.clock(), and os.difftime().

  • Vendored internal Lua function implementations for the subset functions from gopher-lua (required to open the subsets, otherwise entire module is available).
  • Added scripts_VULN_tests into tests/scripts_test.go; tests for function existence.

All tests pass using go version 1.19.3 on Linux.

internal/server/scripts.go Outdated Show resolved Hide resolved
internal/server/scripts.go Outdated Show resolved Hide resolved
internal/server/scripts.go Outdated Show resolved Hide resolved
@program--
Copy link
Contributor Author

@tidwall Do you have a preference between using nested functions versus the current function definitions I've added? (i.e. osClock, osDiffTime, etc.)

I noticed in lStatePool.New() that you implement some Lua package module functions, but nest the function definitions within .New().

I could move the definitions directly into openOsSubset and openBaseSubset so they don't pollute the internal namespace, but I guess that's more of a style choice than anything else.

@tidwall
Copy link
Owner

tidwall commented Nov 21, 2022

I could move the definitions directly into openOsSubset and openBaseSubset so they don't pollute the internal namespace, but I guess that's more of a style choice than anything else.

I'm fine with your approach.

@tidwall tidwall merged commit cc942b2 into tidwall:master Nov 21, 2022
@tidwall
Copy link
Owner

tidwall commented Nov 21, 2022

LGTM. Thanks 👍

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

Successfully merging this pull request may close these issues.

Lua Sanitization
2 participants