Skip to content

Unsafe URL construction in the CodeSnippets cog #3315

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

Open
decorator-factory opened this issue Apr 12, 2025 · 0 comments
Open

Unsafe URL construction in the CodeSnippets cog #3315

decorator-factory opened this issue Apr 12, 2025 · 0 comments

Comments

@decorator-factory
Copy link
Member

decorator-factory commented Apr 12, 2025

Exploitation example:

<https://github.com/python/cpython/blob/main/../../../../users/octocat#L1>

Image

(discord unhelpfully resolves the ..s)

The reason this is happening is this regex matching ../../../../users/octocat as the filename and then blindly substituting it into this URL template. .. in a URL has a similar meaning to UNIX file paths: the parent directory. So the resulting URL (https://api.github.com/repos/python/cpython/contents/../../../../users/octocat?ref=main) means the same as https://api.github.com/users/octocat?ref=main.

Not sure if there's a good fix for this besides just not allowing (\.|%2[eE]){2} in the URL. (Yes, .%2E and %2e%2E do both mean "parent directory", don't you love URI)

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

No branches or pull requests

2 participants
@decorator-factory and others