Skip to content

Commit

Permalink
fix(api)!: only accept json content
Browse files Browse the repository at this point in the history
1. Clients can not send urlencoded/multipart requests.
BREAKING CHANGE: this means that eg an appengine request on the endpoint
`interface_values_path  POST    /v1/:realm_name/devices/:device_id/interfaces/:interface/*path_token`

which previously _could_ be successful with an urlencoded body of `data=2`
will not be successful anymore.

2. Remove `pass: ["*/*"]`
From the [Plug.Parsers documentation](https://hexdocs.pm/plug/Plug.Parsers.html),
"This plug will raise Plug.Parsers.UnsupportedMediaTypeError by default
if the request cannot be parsed by any of the given types and the MIME
type has not been explicitly accepted with the :pass option".

I believe this to be the desired behavior, as the application should return
error code 415 if it is not parsable by one of the specified parsers.

Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
  • Loading branch information
noaccOS committed Aug 1, 2023
1 parent d7997ac commit f03ab15
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- Forward port changes from release 1.1.

### Fixed
- [all] API now only accepts json requests

## [1.1.0] - 2023-06-20
### Fixed
- [astarte_trigger_engine] Allow to decode events that do not contain the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ defmodule Astarte.AppEngine.APIWeb.Endpoint do
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]

plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
parsers: [:json],
json_decoder: Phoenix.json_library()

plug Plug.MethodOverride
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ defmodule Astarte.Housekeeping.APIWeb.Endpoint do
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]

plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
parsers: [:json],
json_decoder: Phoenix.json_library()

plug Plug.MethodOverride
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ defmodule Astarte.Pairing.APIWeb.Endpoint do
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]

plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
parsers: [:json],
json_decoder: Phoenix.json_library()

plug Plug.MethodOverride
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ defmodule Astarte.RealmManagement.APIWeb.Endpoint do
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]

plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
parsers: [:json],
json_decoder: Phoenix.json_library()

plug Plug.MethodOverride
Expand Down

0 comments on commit f03ab15

Please sign in to comment.