Browse Source

Fix hc.api.views.ping to handle non-utf8 data in request body

Fixes: #574
master
Pēteris Caune 3 years ago
parent
commit
829a39f4cf
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 13 additions and 1 deletions
  1. +3
    -0
      CHANGELOG.md
  2. +9
    -0
      hc/api/tests/test_ping.py
  3. +1
    -1
      hc/api/views.py

+ 3
- 0
CHANGELOG.md View File

@ -7,6 +7,9 @@ All notable changes to this project will be documented in this file.
- Switch from croniter to cronsim (vendored in hc.lib.cronsim)
- Change outgoing webhook timeout to 10s, but cap the total time to 20s
### Bug Fixes
- Fix hc.api.views.ping to handle non-utf8 data in request body (#574)
## v1.23.1 - 2021-10-13
### Bug Fixes


+ 9
- 0
hc/api/tests/test_ping.py View File

@ -254,3 +254,12 @@ class PingTestCase(BaseTestCase):
def test_it_rejects_exit_status_over_255(self):
r = self.client.get(self.url + "/256")
self.assertEqual(r.status_code, 400)
def test_it_handles_bad_unicode(self):
csrf_client = Client(enforce_csrf_checks=True)
r = csrf_client.post(self.url, b"Hello \xe9 World", content_type="text/plain")
self.assertEqual(r.status_code, 200)
ping = Ping.objects.get()
self.assertEqual(ping.method, "POST")
self.assertEqual(ping.body, "Hello � World")

+ 1
- 1
hc/api/views.py View File

@ -47,7 +47,7 @@ def ping(request, code, check=None, action="success", exitstatus=None):
scheme = headers.get("HTTP_X_FORWARDED_PROTO", "http")
method = headers["REQUEST_METHOD"]
ua = headers.get("HTTP_USER_AGENT", "")
body = request.body.decode()
body = request.body.decode(errors="replace")
if exitstatus is not None and exitstatus > 0:
action = "fail"


Loading…
Cancel
Save