Help hiding sensitive information in validation responses #4016
Replies: 2 comments
-
|
You can intercept at |
Beta Was this translation helpful? Give feedback.
-
|
It helps with the response sent to the client, but your tracing layer can see the GraphQL error before the formatted response exists. Variable coercion/validation errors are created before resolvers run, so PII can already be present in the error message by the time your handler formats it. I would handle this in two layers:
For example, instead of relying on a scalar/enum/coercion error to say “invalid value X”, let GraphQL accept the opaque string and return your own safe validation error: {
"message": "Invalid value for field",
"extensions": {
"code": "BAD_USER_INPUT",
"field": "ssn"
}
}So the short version is: response masking is good, but observability redaction has to happen before export, and sensitive validation should not depend on GraphQL's default coercion messages. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there, I'm looking for some advice for removing sensitive inputs from validation error messages for PII reasons.
For example the following response:
Is returned from here:
graphql-js/src/execution/values.ts
Lines 125 to 129 in 8c749e9
If possible I'd like to avoid this behaviour for certain fields in my schema which are sensitive.
So far I have attempted to define my own scalars,
SensitiveString,SensitivePhoneNumberetc, throwing a custom error, and in myformatErrorerror handler (using apollo server) manually parsing and removing the sensitive input values. This is important so that Personally Identifiable Information isn't logged or captured by tracing tools.This worked for logging, however tracing tools (datadogs dd-trace in particular) hooks into the execute error response prior to my error handler being activated, meaning that the sensitive information is still captured in traces.
One important thing to note is that this isn't an issue when values are embedded into queries, as a different validation mechanism is used:
graphql-js/src/validation/rules/ValuesOfCorrectTypeRule.ts
Lines 169 to 177 in 8cfa3de
Here I can simply make sure I throw an instance of
GraphQLErrorfrom my custom scalar and custom error message will be respected and not wrapped.Is there a way to make sure the input values wrapping doesn't take place when variables aren't embedded in the query and the
coerceVariableValuesis used?Beta Was this translation helpful? Give feedback.
All reactions