Hi We use ktor 3 with ContentNegotiation Are there...
# ktor
l
Hi We use ktor 3 with ContentNegotiation Are there ways to protect us against XSS? By escaping or sanitizing every field that is unserialized?
a
Can you describe your use case to protect against XSS in more detail?
l
we have a rest server, clients are • pure rest clients • a react app
a client could inject some html markups in our database, then if there is a flaw in react app it could eventually be executed
a
Do you mean for the kotlinx.serialization content converter?
l
Yes, actually we set ktor with
Copy code
install(ContentNegotiation) Httpp
Reusing the example of the plugin we have serializable data classes
Copy code
@Serializable
data class Customer(val id: Int, val firstName: String, val lastName: String)
And ktor does the deserialization automatically
Copy code
post("/customer") {
    val customer = call.receive<Customer>()
In this example, I'd like
firstName
and
lastName
to be sanitized I'd like to set it up at one place and make it work for all routes
a
I can only recommend validating the properties in the
init
block of the
Customer
class.
👍 1
h
Either that, or make an interceptor that you add to the calls
👍 1