-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NP] route validation does not properly parse multipart/form-data payloads #56951
Comments
Pinging @elastic/kibana-platform (Team:Platform) |
TIL, when using JOI automatically tries to convert strings to proper types by default, which explains why this works in legacy route handlers:
if (typeof value === 'string' && options.convert) {
internals.safeParse(value, result);
} However in NP we are using kibana/packages/kbn-config-schema/src/internals/index.ts Lines 369 to 382 in bbe700d
Should the condition on all our coerce block be changed to no longer ignore the convert option? if (value !== undefined && !options.convert && !Array.isArray(value)) { The following test does pass with the suggested modification, and fails otherwise (so does the integration test in the initial description) test.only('uses convert', () => {
const type = schema.arrayOf(schema.string());
expect(type.validate('["hello"]', {}, 'foo-namespace')).toMatchInlineSnapshot(`
Array [
"hello",
]
`);
}); However, as One option would be to use kibana/packages/kbn-config-schema/src/types/type.ts Lines 71 to 82 in 94b2b83
One other possible workaround (taking the description example) would be to type Overall, I think the less impacting solution is still to change our custom WDYT? |
One issue that has come up is that the NP router does not parse query param values. So if you have a request like Would this change also fix that situation? |
Do we have version this needs to block on? 7.7? |
Would need to manually test to be sure, but it would probably also fix that yes. As long as the stringified value is parsable as expected type, it would work. |
Related to #56734
While trying to migrate the
/api/saved_objects/_resolve_import_errors
route (insrc/legacy/server/saved_objects/routes
), I encountered what seems to be a regression in multipart-data handling in new platform.The route accepts multipart form-data payload, that contains both a
file
and some additional data (retries
):In legacy, the additional
retries
data is properly parsed and converted to the expected array typeWhen doing the equivalent in new platform:
The
retries
property received a raw string causing the validation to fails. In particularkibana/test/api_integration/apis/saved_objects/resolve_import_errors.js
Lines 32 to 44 in 8e9a8a8
fails with following error:
[request body.retries]: expected value of type [array] but got [string]'
I'm not sure if the regression is caused by a configuration difference in our hapi route config (the root server is the same in LP and NP, so it cannot be a root configuration mismatch), or if the difference if in the use of
schema
instead or rawjoi
. Maybejoi
was parsing strings when expecting another type and we are not?The text was updated successfully, but these errors were encountered: