Open rikukissa opened 2 months ago
I believe this being low priority, as no specific security risk was found even though the validations aren't there. Inputting HTML-tags doesn't still render them as HTML tags so the security risk is low. Correct me if I'm mistaken, but is this a feature rather than a security fix?
This is ultimately a data hygiene question with also links to security. As we lack a proper holistic approach to incoming data validation, it's really just a matter of time before someone finds an exploit. The exploit could also be submitting a value not part of a dropdown select for instance or the client sending a record state not known to us. These things would cause data corruption and exceptions potentially blocking users from using the application. XSS is part of this but not the whole story.
Points to discuss this week with Tameem:
validators.js
, how can we trustfully run custom JS in the backend? --> may not make sense.Do you think it would make sense to bring this a step closer to GraphQL? I'm thinking a lot of the request body shape & field validation happens currently by the GraphQL schema. Is there a way to leverage / extend that to cater for more expressive validations?
https://www.apollographql.com/blog/graphql-validation-using-directives This at least looks pretty decent
Or is it better to keep the validation separated for future where we might not use GraphQL?
That could be a good option for the forms we control. For the configurable validations in forms, we could do something similar for TEXT:
{
...
backendValidation?: {
pattern?: Regexp
maxLength?: number
format?: 'email' | '...'
}
}
Then add the option validation for SELECT's as we should know all the possible options?
Yea 👍 That also made me think that maybe instead of type: 'TEXT'
we could have type: 'EMAIL'
etc
For forms, it might be easiest to implement this as part of #7052
@makelicious @naftis please note that this tech debt issue should be commenced as part of custom vital events work. @Nil20 @Zangetsu101 @tumbledwyer there will be work to do with user creation also.
For form data submission and basic events like declaring, we should postpone adding validation until custom events. For things like user creation however this should be implemented asap
Description
UserInput
{[fieldId: string]: Validator}
signatureSecurity assessment details
Technical Overview
Potential Impact if Exploited
Recommendations
Tech tasks
Step 1:
Validate the incoming payload to the public FHIRs APIs such as FHIR Locations to ensure no traversing is possible
Step 2:
Validate the incoming payloads for the create user form
Option 1
1) create
packages/form-validations
which generates a package@opencrvs/form-validations
that the frontend and gateway can use 2) publish the package, so that country-config can use the type definitions 3) create a gateway function that can be used in the createBirthRegistration routes for example, that fetches forms and validates the corresponding fields. This can be difficult with our current flexible mapping ? Time to move into aRecord<FormFieldIdentifier, string>
type of a GraphQL-model? 4) import the shared functions from the form-validations package similarly as we currently doOption 2
The first option can get difficult with mapping, so we could start with only validating the forms that are known to us. So handle the country specific forms later.