Git Product home page Git Product logo

Comments (3)

matthewwardrop avatar matthewwardrop commented on July 19, 2024

This is related to an issue on patsy pydata/patsy#156, where @FerusAndBeyond points out that running:

from formulaic import model_matrix
model_matrix('sys.exit()', ...)

will kill the running python service. Is there a way to protect formulaic from code injection?

from formulaic.

tomicapretto avatar tomicapretto commented on July 19, 2024

At the moment, formulae does not use eval() (see here), but it is still vulnerable to sys.exit() calls if you have sys loaded in the environment where design_matrices() is called.

I do think we could port something similar to Formulaic and attempt to ban people calling functions from certain modules.

EDIT

You could have the following scenarios

  1. sys module is not loaded
model_matrix("sys.exit()")

No problem here (I think?). It is going to raise an error because sys is not going to be found.

  1. sys module is loaded
model_matrix("sys.exit()")

Python service is killed

  1. sys module is loaded but developer prevented it from being used
formulaic.disable_modules(["sys"])
model_matrix("sys.exit()")

Python service is not killed. An error is raised because you can't call anything from the sys module.

Does it make sense?

from formulaic.

matthewwardrop avatar matthewwardrop commented on July 19, 2024

Yeah, that is correct!

It should also be noted model_matrix is a user-convenience function. Software libraries should use Formula(...).get_model_matrix which requires you to explicitly nominate the evaluation context, and it does not add the current evaluation context by default. You can simulate that in model_matrix by passing None or the the evaluation context dictionary via model_matrix(context=...), which then replaces the automatically imputed context.

I don't see avoiding eval here to be that useful, since we're not actually adding any security if we will call the functions represented in the string anyway. I think the bigger thing is getting users familiar with the security risks, and using Formula().get_model_matrix() in library code.

from formulaic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.