Skip to content

Formatting a datetime expires value uses the process locale for day and month names #658

Open

Description

@sophiecarreras

What happens

When expires is passed as a datetime, it is formatted with strftime('%a, %d %b %Y %H:%M:%S GMT'), which uses the process locale for %a and %b. If the host program has called setlocale for a non-English locale, the header value has non-English names and is not a valid HTTP date. Other HTTP code in the library guards against this by using the C locale.

Where

b2sdk/_internal/bucket.py:143-145 (_merge_file_info_and_headers_params); the guard elsewhere is at b2sdk/_internal/b2http.py:70-76.

Why it matters

Impact: Wrong request or result, silent. Severity: Medium, because it needs the host application to have changed LC_TIME, which Python does not do by default.

How to check

Call locale.setlocale(locale.LC_TIME, 'de_DE.UTF-8') (if installed) and upload with expires=datetime(...); the stored b2-expires value has German names. Found by reading the code, not reproduced.

Version

Seen at v2.13.4. Present on the default branch: present.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions