Skip to content

Updated error response to hide error stack in case of JsonMappingException - #16821

Merged
cryptoe merged 7 commits into
apache:masterfrom
deep-bi:deep/feature/handle-json-mapping-exception-gracefully
Nov 21, 2024
Merged

cryptoe merged 7 commits into
apache:masterfrom
deep-bi:deep/feature/handle-json-mapping-exception-gracefully

Conversation

@vivek807

@vivek807 vivek807 commented Jul 30, 2024 •

Copy link
Copy Markdown
Contributor

Updated error response to hide error stack in case of JsonMappingException if druid.server.http.showDetailedJsonMappingError is configured as false

Description

Currently when Jackson failed to map request payload either due to required fields or invalid types, it end up exposing too much details about the internal model with 400 response. This can be concerning from security point of view.

It is likely that an attacker may be able to exploit this indeterminate state to access unauthorized functionality, or worse, create, modify or destroy data. Error messages may also aid in the identification of other attacks such as buffer overflows and SQL injection, and can generally contribute to an overall weaker security posture.

The same physical paths, versioning information, stack traces' content, and other data can be gathered and used to help further an attack.

Fixed the bug

Added flag druid.server.http.showDetailedJsonMappingError similar druid.server.http.showDetailedJettyError to configure error message detail.

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

…ption if `druid.server.http.showDetailedJettyError` is configured as `false`
@vivek807
vivek807 marked this pull request as ready for review August 1, 2024 05:18
…tailedJettyErrors` for the json mapping errors.

Updated docs
Addressed review comments
@FrankChen021

FrankChen021 commented Aug 12, 2024 •

Copy link
Copy Markdown
Member
  1. What kind of response now is if such exception is raised?
  2. IMO, there's no need to provide a configuration to hide the error stack, we can always hide the internal errors and show better messages. If we design it in this way, in the future, we would have lots of configurations like showDetailedXXXError

@vivek807

vivek807 commented Aug 13, 2024 •

Copy link
Copy Markdown
Contributor Author
  1. What kind of response now is if such exception is raised?
  2. IMO, there's no need to provide a configuration to hide the error stack, we can always hide the internal errors and show better messages. If we design it in this way, in the future, we would have lots of configurations like showDetailedXXXError

Current error response looks something like this:

{"error":"Cannot construct instance of
`org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexIOConfig`,
problem: At least one of properties[[firehose, inputSource]] must be present\n at
[Source: (org.eclipse.jetty.server.HttpInputOverHTTP); line: 1, column: 69] (through
reference chain:
org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexSupervisorTask[\"spe
c\"]-
>org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexIngestionSpec[\"ioC
onfig\"])"}

We added the flag because we may need to view detailed errors for debugging or other purposes. Initially, we used showDetailedJettyError, but that name was too specific to Jetty errors.
To avoid such flag, I think we can add a generic flag or live without it by adding detail message to logs only.

@FrankChen021

Copy link
Copy Markdown
Member
  1. What kind of response now is if such exception is raised?
  2. IMO, there's no need to provide a configuration to hide the error stack, we can always hide the internal errors and show better messages. If we design it in this way, in the future, we would have lots of configurations like showDetailedXXXError

Current error response looks something like this:

{"error":"Cannot construct instance of
`org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexIOConfig`,
problem: At least one of properties[[firehose, inputSource]] must be present\n at
[Source: (org.eclipse.jetty.server.HttpInputOverHTTP); line: 1, column: 69] (through
reference chain:
org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexSupervisorTask[\"spe
c\"]-
>org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexIngestionSpec[\"ioC
onfig\"])"}

We added the flag because we may need to view detailed errors for debugging or other purposes. Initially, we used showDetailedJettyError, but that name was too specific to Jetty errors. To avoid such flag, I think we can add a generic flag or live without it by adding detail message to logs only.

Thanks for the info.
For the debugging purpose, we can add these information to logs. For the HTTP Response, we can keep only the info like:

Cannot construct instance of
`org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexIOConfig`,
problem: At least one of properties[[firehose, inputSource]] must be present

@FrankChen021

Copy link
Copy Markdown
Member

But if the http response is like:

Cannot construct instance of
`org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexIOConfig`,
problem: At least one of properties[[firehose, inputSource]] must be present

I think such information is clear for the users for troubleshooting and there's no need to add stack trace to logs.

Removed flag
Updated docs and unit tests.
@vivek807

Copy link
Copy Markdown
Contributor Author

But if the http response is like:

Cannot construct instance of
`org.apache.druid.indexing.common.task.batch.parallel.ParallelIndexIOConfig`,
problem: At least one of properties[[firehose, inputSource]] must be present

I think such information is clear for the users for troubleshooting and there's no need to add stack trace to logs.

Done, thanks

@vivek807
vivek807 requested a review from cryptoe August 21, 2024 02:56
@vivek807
vivek807 requested a review from cryptoe October 11, 2024 12:50
@vivek807

vivek807 commented Nov 5, 2024

Copy link
Copy Markdown
Contributor Author

Hi @FrankChen021 / @cryptoe , Just checking in—could you please review the changes once more and let me know if anything is still pending?

@cryptoe
cryptoe merged commit bb44f85 into apache:master Nov 21, 2024
@cryptoe

cryptoe commented Nov 21, 2024

Copy link
Copy Markdown
Contributor

@vivek807 Thank you for the patience. The change LGTM.

@adarshsanjeev adarshsanjeev added this to the 32.0.0 milestone Jan 16, 2025
riovic918data pushed a commit to riovic918data/druid that referenced this pull request Jun 12, 2026
…ption (apache#16821)

Added flag druid.server.http.showDetailedJsonMappingError similar druid.server.http.showDetailedJettyError to configure error message detail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants