Skip to content

Allow to set change/disable destination array #113

Closed
@briedis

Description

@briedis

I came across a project, which logs it's $_SERVER and $_ENV values in log file on errors, and that kinda sucks. I ended up with a small snippet, that clears $_ENV and $_SERVER from loaded values, but, getenv() function still works properly.

What do you thing about this option? I know this is a specific situation, but sometimes, a dev can by accident enable error reporting on production, which sometimes (Yii2, for example), dumps the whole ENV and SERVER array to the user. If that happens, all API keys, passwords, etc are compromised.

My current snippet:

// Anonymous function used so we don't introduce variables in global scope
call_user_func(function () {
    $oldEnvKeys = array_keys($_ENV);

    $dotEnv = new \Dotenv\Dotenv(__DIR__);
    $dotEnv->load();

    // Delete DotEnv loaded values from $_ENV and $_SERVER (we only use getenv function, to retrieve them)
    foreach ($_ENV as $k => $v) {
        if (!in_array($k, $oldEnvKeys)) {
            unset($_ENV[$k]);
            unset($_SERVER[$k]);
        }
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions