-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add a bunch of missing urllib.parse.quote calls #1976
Conversation
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Go away, stale bot. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Any chance of this getting reviewed and merged, @s-t-e-v-e-n-k? It's a bugfix with possible security implications. (I would be happy to leave for you to handle it whenever you get to it, but, well, by using the stale bot you're not leaving me that choice; I have to either nag you about it every few months or have it be automatically thrown away.) |
This is very interesting, thanks for the thorough explanation. Can you please rerun the regexp with latest main HEAD and also consider the following regexp: Those urls can also be constructed without |
Conflicts: github/Organization.py
Conflicts: github/Organization.py
Conflicts: github/Organization.py github/Repository.py github/Team.py
Conflicts: github/Migration.py github/Team.py
Conflicts: github/Team.py
Conflicts: github/Repository.py
9e3cb38
to
08ba61a
Compare
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #1976 +/- ##
==========================================
- Coverage 96.73% 96.68% -0.05%
==========================================
Files 142 142
Lines 14499 14559 +60
==========================================
+ Hits 14025 14077 +52
- Misses 474 482 +8 ☔ View full report in Codecov by Sentry. |
ed31888
to
9d5c39d
Compare
Okay, I've now:
Should be ready for another round of review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work, thanks for the effort!
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [PyGithub](https://togithub.com/pygithub/pygithub) | `==2.1.1` -> `==2.2.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>pygithub/pygithub (PyGithub)</summary> ### [`v2.2.0`](https://togithub.com/PyGithub/PyGithub/releases/tag/v2.2.0) [Compare Source](https://togithub.com/pygithub/pygithub/compare/v2.1.1...v2.2.0) #### Breaking Changes The `github.Comparison.Comparison` instance returned by `Repository.compare` provides a `commits` property that used to return a `list[github.Commit.Commit]`, which has now been changed to `PaginatedList[github.Commit.Commit]`. This breaks user code that assumes a `list`: ```python commits = repo.compare("v0.6", "v0.7").commits no_of_commits = len(commits) # will raise a TypeError ``` This will raise a `TypeError: object of type 'PaginatedList' has no len()`, as the returned `PaginatedList` does not support the `len()` method. Use the `totalCount` property instead: ```python commits = repo.compare("v0.6", "v0.7").commits no_of_commits = commits.totalCount ``` #### New features - Add support to call GraphQL API #### Improvements - Add parent_team_id, maintainers and notification_setting for creating and updating teams. by [@​Cheshirez](https://togithub.com/Cheshirez) in [https://github.com/PyGithub/PyGithub/pull/2863](https://togithub.com/PyGithub/PyGithub/pull/2863) - Add support for issue reactions summary by [@​smuzaffar](https://togithub.com/smuzaffar) in [https://github.com/PyGithub/PyGithub/pull/2866](https://togithub.com/PyGithub/PyGithub/pull/2866) - Support for DependabotAlert APIs by [@​coopernetes](https://togithub.com/coopernetes) in [https://github.com/PyGithub/PyGithub/pull/2879](https://togithub.com/PyGithub/PyGithub/pull/2879) - Derive GraphQL URL from base_url by [@​EnricoMi](https://togithub.com/EnricoMi) in [https://github.com/PyGithub/PyGithub/pull/2880](https://togithub.com/PyGithub/PyGithub/pull/2880) - Make `Repository.compare().commits` return paginated list by [@​EnricoMi](https://togithub.com/EnricoMi) in [https://github.com/PyGithub/PyGithub/pull/2882](https://togithub.com/PyGithub/PyGithub/pull/2882) - Add missing branch protection fields by [@​treee111](https://togithub.com/treee111) in [https://github.com/PyGithub/PyGithub/pull/2873](https://togithub.com/PyGithub/PyGithub/pull/2873) - Add `include_all_branches` to `create_repo_from_template` of `AuthenticatedUser` and `Organization` by [@​janssonoskar](https://togithub.com/janssonoskar) in [https://github.com/PyGithub/PyGithub/pull/2871](https://togithub.com/PyGithub/PyGithub/pull/2871) - Add and update organisation dependabot secrets by [@​mohy01](https://togithub.com/mohy01) in [https://github.com/PyGithub/PyGithub/pull/2316](https://togithub.com/PyGithub/PyGithub/pull/2316) - Add missing params to `Organization.create_repo` by [@​tekumara](https://togithub.com/tekumara) in [https://github.com/PyGithub/PyGithub/pull/2700](https://togithub.com/PyGithub/PyGithub/pull/2700) - Update allowed values for `Repository` collaborator permissions by [@​flying-sheep](https://togithub.com/flying-sheep) in [https://github.com/PyGithub/PyGithub/pull/1996](https://togithub.com/PyGithub/PyGithub/pull/1996) - Support editing PullRequestReview by [@​ColasGael](https://togithub.com/ColasGael) in [https://github.com/PyGithub/PyGithub/pull/2851](https://togithub.com/PyGithub/PyGithub/pull/2851) - Update attributes after calling `PullRequestReview.dismiss` by [@​ColasGael](https://togithub.com/ColasGael) in [https://github.com/PyGithub/PyGithub/pull/2854](https://togithub.com/PyGithub/PyGithub/pull/2854) - Add `request_cve` on `RepositoryAdvisories` by [@​JLLeitschuh](https://togithub.com/JLLeitschuh) in [https://github.com/PyGithub/PyGithub/pull/2855](https://togithub.com/PyGithub/PyGithub/pull/2855) - Filter collaborators of a repository by permissions by [@​notmicaelfilipe](https://togithub.com/notmicaelfilipe) in [https://github.com/PyGithub/PyGithub/pull/2792](https://togithub.com/PyGithub/PyGithub/pull/2792) - Set pull request to auto merge via GraphQL API by [@​heitorpolidoro](https://togithub.com/heitorpolidoro) in [https://github.com/PyGithub/PyGithub/pull/2816](https://togithub.com/PyGithub/PyGithub/pull/2816) - Support Environment Variables and Secrets by [@​AndrewJDawes](https://togithub.com/AndrewJDawes) in [https://github.com/PyGithub/PyGithub/pull/2848](https://togithub.com/PyGithub/PyGithub/pull/2848) - Update workflow.get_runs & pullrequest.add_to_assignees function signature by [@​sd-kialo](https://togithub.com/sd-kialo) in [https://github.com/PyGithub/PyGithub/pull/2799](https://togithub.com/PyGithub/PyGithub/pull/2799) - Add `GithubObject.last_modified_datetime` to have `last_modified` as a `datetime` by [@​chouetz](https://togithub.com/chouetz) in [https://github.com/PyGithub/PyGithub/pull/2772](https://togithub.com/PyGithub/PyGithub/pull/2772) - Add support for global advisories and unify some shared logic with repository advisories by [@​crimsonknave](https://togithub.com/crimsonknave) in [https://github.com/PyGithub/PyGithub/pull/2702](https://togithub.com/PyGithub/PyGithub/pull/2702) - Add `internal` as valid Repository visibility value by [@​AndrewJDawes](https://togithub.com/AndrewJDawes) in [https://github.com/PyGithub/PyGithub/pull/2806](https://togithub.com/PyGithub/PyGithub/pull/2806) - Add support for issue comments reactions summary by [@​smuzaffar](https://togithub.com/smuzaffar) in [https://github.com/PyGithub/PyGithub/pull/2813](https://togithub.com/PyGithub/PyGithub/pull/2813) #### Bug Fixes - Add a bunch of missing urllib.parse.quote calls by [@​ExplodingCabbage](https://togithub.com/ExplodingCabbage) in [https://github.com/PyGithub/PyGithub/pull/1976](https://togithub.com/PyGithub/PyGithub/pull/1976) - Fix Variable and Secret url bugs by [@​AndrewJDawes](https://togithub.com/AndrewJDawes) in [https://github.com/PyGithub/PyGithub/pull/2835](https://togithub.com/PyGithub/PyGithub/pull/2835) #### Maintenance - Update the class name for NetrcAuth in the examples by [@​vinnybod](https://togithub.com/vinnybod) in [https://github.com/PyGithub/PyGithub/pull/2860](https://togithub.com/PyGithub/PyGithub/pull/2860) - Move build to PEP517 by [@​trim21](https://togithub.com/trim21) in [https://github.com/PyGithub/PyGithub/pull/2800](https://togithub.com/PyGithub/PyGithub/pull/2800) - Use new type assert functions in `Repository` by [@​trim21](https://togithub.com/trim21) in [https://github.com/PyGithub/PyGithub/pull/2798](https://togithub.com/PyGithub/PyGithub/pull/2798) - PyTest: Move config to pyproject.toml by [@​Borda](https://togithub.com/Borda) in [https://github.com/PyGithub/PyGithub/pull/2859](https://togithub.com/PyGithub/PyGithub/pull/2859) - codespell: ignore-words-list by [@​Borda](https://togithub.com/Borda) in [https://github.com/PyGithub/PyGithub/pull/2858](https://togithub.com/PyGithub/PyGithub/pull/2858) - Improve fix-headers.py script by [@​EnricoMi](https://togithub.com/EnricoMi) in [https://github.com/PyGithub/PyGithub/pull/2728](https://togithub.com/PyGithub/PyGithub/pull/2728) - Remove dependency on python-dateutil by [@​lazka](https://togithub.com/lazka) in [https://github.com/PyGithub/PyGithub/pull/2804](https://togithub.com/PyGithub/PyGithub/pull/2804) - CI: update precommit & apply by [@​Borda](https://togithub.com/Borda) in [https://github.com/PyGithub/PyGithub/pull/2600](https://togithub.com/PyGithub/PyGithub/pull/2600) - Docs: Fix parameter order according to Version 2.1.0 by [@​nad182](https://togithub.com/nad182) in [https://github.com/PyGithub/PyGithub/pull/2786](https://togithub.com/PyGithub/PyGithub/pull/2786) - Add missing GitHub classes to docs by [@​EnricoMi](https://togithub.com/EnricoMi) in [https://github.com/PyGithub/PyGithub/pull/2783](https://togithub.com/PyGithub/PyGithub/pull/2783) - CI: Fix mypy error by ignoring override by [@​EnricoMi](https://togithub.com/EnricoMi) in [https://github.com/PyGithub/PyGithub/pull/2779](https://togithub.com/PyGithub/PyGithub/pull/2779) **Full Changelog**: PyGithub/PyGithub@v2.1.1...v2.2.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/lettuce-financial/github-bot-signed-commit). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xNTMuMiIsInVwZGF0ZWRJblZlciI6IjM3LjE1My4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
There were previously lots of places in PyGithub where public methods take a string value and interpolate it directly into a URL without URL-encoding it. This results in a bunch of bugs; for instance, trying to get a branch with a
#
in its name fails.It also conceivably introduces some kind of security issue somewhere, since anywhere that an application is passing a user-provided value to one of these methods, a user can exploit this to cause a request to be sent to a malformed URL or to add arbitrary additional path segments to the URL after the interpolated value or to add an arbitrary query string (although I have not been able to think of a realistic exploit based on this, and am not confident that one really exists).
To try to fix this, I did a regex search across the whole codebase for
which finds expressions like
or
and audited each such expression. If the value being interpolated into the URL was already being explicitly URL-encoded in the method, I left it alone. If it was guaranteed via an
assert isinstance(...)
check to be a number, I left it alone. If it was the._identity
property of aPyGithub
object whose_identity
is guaranteed not to contain any special characters in need of URL-encoding, I left it alone. In all other cases, it was an arbitrary string, and in those cases, I URL-encoded it. I did this even in cases where the argument represented something like a GitHub username which cannot legally contain any special characters that need URL-encoding, for a couple of reasons:foo?bar
, it still seems like the correct thing for the library to do is to faithfully encode that username and send it to the API, and get back an appropriate error from GitHub, rather than sending a malformed URL or a URL where?bar
is treated as a query string (which might produce a seemingly-nonsensical error that complains about userfoo
not existing, or worse, might actually return existing userfoo
).I've manually tested my change to check it fixes getting a branch by name when the branch name contains a
#
character. Here's an attempt to get such a branch without this change:And here's an attempt with this change:
I haven't tested anything else, and indeed am not familiar with several of the API calls I've touched in this PR. I'd appreciate if a maintainer familiar with them could review my changes sceptically, and maybe test them if needed.
Note that this is kind of a breaking change, since some users may have worked around this bug by calling
urllib.parse.quote
on values in their own code before passing them to PyGithub, and such values will now get doubly encoded. As such, this should be called out as a breaking change in the change notes.