Skip to content

Reject path-like locale names in Locale.load - #1031

Open
Sharadhi-v98 wants to merge 1 commit into
python-pendulum:masterfrom
Sharadhi-v98:locale-load-reject-paths
Open

Sharadhi-v98 wants to merge 1 commit into
python-pendulum:masterfrom
Sharadhi-v98:locale-load-reject-paths

Conversation

@Sharadhi-v98

Copy link
Copy Markdown

Locale.load joins the locale name onto the locales package directory to check that it exists, then imports it as a submodule. The name comes straight from the locale argument of format, diff_for_humans, in_words, from_format and set_locale, and nothing checks that it is a plain name. An absolute path replaces the package directory in the join and ../ walks out of it, so the existence check runs against whatever path the caller supplied. When that path exists the import fails with ModuleNotFoundError instead of the ValueError an unknown locale raises: set_locale("/etc/passwd") gives ModuleNotFoundError while set_locale("/etc/nope") gives ValueError, which tells the caller whether the path is there. A name that is not a plain locale identifier is now rejected with the usual ValueError before the filesystem is touched.

  • Added tests for changed code.
  • Updated documentation for changed code.

This branch has not been deployed

No deployments
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.

1 participant