You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I came across a bug in the home assistant REST API that happens when you send a string in quotes in the request body. This affects POST /api/template and POST /api/state. Homeassistant responds with a 500 code because it expects a dictionary json but it doesn't check for that precisely, because strings are getting parsed as valid json by aiohttp.
You can reproduce the same error on both endpoints with the following snippets.
To reproduce the error on POST /api/template
Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (api) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of api can trigger bot actions by commenting:
@home-assistant close Closes the issue.
@home-assistant rename Awesome new title Renames the issue.
@home-assistant reopen Reopen the issue.
@home-assistant unassign api Removes the current integration label and assignees on the issue, add the integration domain after the command.
@home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
@home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.
The problem
Hello! I came across a bug in the home assistant REST API that happens when you send a string in quotes in the request body. This affects
POST /api/template
andPOST /api/state
. Homeassistant responds with a 500 code because it expects a dictionary json but it doesn't check for that precisely, because strings are getting parsed as valid json by aiohttp.You can reproduce the same error on both endpoints with the following snippets.
To reproduce the error on
POST /api/template
which outputs
The corresponding stack track in HA core is:
Second, to reproduce the error on
POST /api/states
The corresponding HA core stack trace:
What version of Home Assistant Core has the issue?
core-2024.12.5
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Core
Integration causing the issue
api
Link to integration documentation on our website
https://www.home-assistant.io/integrations/api/
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
My HA core installation is the HA core docker image, but I don't think that's too relevant.
The parsing logic is correct in
POST /api/event
by checking forisinstance(event_data, dict)
. Specifically at https://github.com/home-assistant/core/blob/dev/homeassistant/components/api/__init__.py#L337.This issue might also affect
POST /api/services/<domain>/<service>
because https://github.com/home-assistant/core/blob/bf59241dabf93da9929709fc0c5a866e2c0b2790/homeassistant/components/api/__init__.py#L385C9-L390C14 doesnt check forisinstance(data, dict)
either. But since its possible for services to accept strings in addition to dicts, I'm not sure if thats an issue yet.The text was updated successfully, but these errors were encountered: