Skip to content

Invalid POSTed UTF-8 is accepted and stored, causing JSON GET endpoints to fail #42

@wandernauta

Description

@wandernauta

Trifecta does not generally check that the string values it receives in POST requests are valid UTF-8, instead passing along the bytes as-is. SQLite will for the most part do the same. However, nlohmann's json will not, and cannot per JSON spec; instead, it will throw on invalid sequences, causing any GET endpoints that try to include bad UTF-8 in their JSON responses to fail.

For robustness, it may be better to already refuse POST requests that have these invalid values, before storing the values in the database. Actual browsers will not make these kinds of requests.

An example that does not require authentication, but which does need direct access to Trifecta (so without nginx), would be the following:

curl -H "X-Real-IP: $(printf '\xc3\x28')" -F user=@<(printf admin) http://localhost:3456/get-signin-email

After this request, the admin panel's sessions table would now include the attacker-provided X-Real-Ip value, but this is invalid. The app logs:

/all-sessions: exception for An error occurred: [json.exception.type_error.316] invalid UTF-8 byte at index 1: 0x28

And the UI appears broken:

Screenshot

Other examples would be e.g. putting invalid UTF-8 into post titles, image captions, user-agent headers, email addresses, and so on, but those would require authentication.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions