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

fix: only send a restricted set of environment variables #188

Merged
merged 9 commits into from
Jan 23, 2025

Conversation

stympy
Copy link
Member

@stympy stympy commented Jan 22, 2025

Like our Ruby client, we need to prevent sending environment variables that aren't related to a web request.

@stympy stympy requested review from joshuap and subzero10 January 22, 2025 22:20
@stympy
Copy link
Member Author

stympy commented Jan 22, 2025

@subzero10 can you arrange for someone who actually knows some Python to get the tests back to passing? :)

@subzero10
Copy link
Member

@subzero10 can you arrange for someone who actually knows some Python to get the tests back to passing? :)

Yeap, I can do that.
Though, on first look it appears that some tests are failing because of the changes in this PR.

For example, this test is looking for
Content-Type, Content-Length and Host but they are not found. Content-Type is found in CGI_ALLOWLIST but it has a different format. I think the check could be improved:

def filter_env_vars(data):
    if type(data) != dict:
        return data

    filtered_data = {}
    for key, value in data.items():
        # Normalize key to uppercase with underscores
        normalized_key = key.upper().replace("-", "_")  
        if normalized_key.startswith('HTTP_') or normalized_key in CGI_ALLOWLIST:
            # Make sure to preserve the original key casing in the output
            filtered_data[key] = value  
    return filtered_data

@stympy stympy changed the title Only send a restricted set of environment variables fix: only send a restricted set of environment variables Jan 23, 2025
Copy link
Member

@subzero10 subzero10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ready to merge :)

@stympy stympy merged commit 63f0af9 into master Jan 23, 2025
19 checks passed
@stympy stympy deleted the filter-environment-variables branch January 23, 2025 17:53
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.

3 participants