Stop Axum’s JSON extractor from reporting errors that give hackers clues to what they're doing wrong #3301
-
SummaryHello, Preface: I'm very new to all this: Rust, Axum, etc. See: #1116 (comment) I think it's great that Axum's JSON extractor reports errors, but I don't want this behavior in my production application because it can be used by hackers to figure out, step-by-step, what they're doing wrong. For example, suppose my REST API is accepting a PUT of:
Via this handler:
All a hacker has to do is start making PUTs and they'll receive detailed instructions on how to construct the appropriate data structure. PUT an empty JSON body and you'll be told:
PUT a JSON body with
And so on. The REST API I'm building is not for the peoples. 🙂 It's for my application alone. There doesn't seem to be a good way to prevent this from happening. All the Gen AI answers I get for this question don't compile or involve a lot of complexity (such as building my own custom JSON extractor), and I'm looking for an easier, simpler way to turn these JSON extraction errors off, and possibly other errors like them I'm not aware of. What I came up with was building a middleware that does this:
So, my questions are: 1) Does this seem like a good solution? 2) Should Axum provide a way to do this? Thanks! axum version0.8.3 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
First and foremost, don't build your security on an assumption that an attacker does not know your payload schema. If you want to have at least basic security, assume they have access to the source code. For your actual question, see |
Beta Was this translation helpful? Give feedback.
First and foremost, don't build your security on an assumption that an attacker does not know your payload schema. If you want to have at least basic security, assume they have access to the source code.
For your actual question, see
WithRejection
and specifically thecustomize-extractor-error
example.