Skip to content

Security concern around literal_eval() of all discovered env vars #113

@applio

Description

@applio

In donfig.config_obj.collect_yaml(), currently ast.literal_eval() is called on every discovered environment variable's value to provide users with the ability to dynamically set values through code. While this feature can be quite valuable in certain use cases, it does raise some security concerns.

One hypothetical but specific example of how this can become a security issue: because by design, environment variables are discovered by Donfig at runtime, a malicious actor could set an additional environment variable (using Dask as an example, a novel env var named DASK_NOBODY_EXPECTS) in an unsuspecting user's shell and if the value of that env var is a string containing a valid Python expression, it would be run by the unsuspecting user with that user's privileges.

It would be preferable to have the ability to disable or enable the attempted use of ast.literal_eval() on each and every discovered env var. It would also be preferable to have this dynamic-eval feature disabled by default and only enabled explicitly when its value outweighs any associated security concerns. Enabling the feature should only be possible programmatically and not via an environment variable.

If others agree that this is a change worth implementing, it could be as simple as exposing a new input argument on donfig.config_obj.Config.__init__() and donfig.config_obj.collect_yaml() which enables/disables the use of ast.literal_eval() and defaults to False.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions