-
Notifications
You must be signed in to change notification settings - Fork 265
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
Forbidden characters #619
Comments
Feedback de Antonio Plasencia:
|
El problema que veo al utilizar HTML encoding para codificar los caracteres prohibidos en las respuestas es que introduciría a su vez un caracter prohibido, ya que la condificación sigue el formato "&xxx;", es decir usa el ";". ¿O quizás estoy interpretando mal lo que propones? Por otra parte, revisando la referencia de Owasp que mandas, no parece que tengan librería para C++ (lenguage de implementación de Orion CB). |
El ";" por sí sólo no supondría un riesgo si el resto de caracteres mencionados se codifican en entidades HTML. En este sentido, también incluiría los paréntesis para evitar riesgos cuando los datos acaben en scripts. Por otra parte, si ESAPI no está disponible para C++ no sé si se podría llegar a utilizar (quizás a través de un intérprete de Python, pero en estos temas me pierdo ya completamente). Si no es posible habría que codificarlo "in house". |
Aclarado que ";" por si solo no es un problema, entonces podemos utilizar codificación HTML. No creo que haya problema a codificaciones "in house" ( @kzangeli es un experto en la materia ;) |
Añadidos paréntesis en el body del issue al conjunto de caracteres prohibidos. |
Have you considered when the Injection is placed within the URL itself? See example at: https://jirapdi.tid.es/browse/DM-243 In general the less information in error responses the better. |
Good point. |
Feature partially implemented in PR #631 |
Feature partially implemented in PR #641 |
Although most of the work has been done in PRs #631 and #641, user input "bypass" in some cases could be potentially exploited for script injection. E.g the "Entity id 'E1'" message in the following response:
Some similar happens with errors related with pagination parameters. The following "algorithm" could be used for detecting these cases: The problem is in error messages and in particular in the "details" field of the statusCode or errorCode objects (code and reasonPhrase are "fixed"). This is the unique case in which the client input may "bypass" to the response (all the others responsed fields are rendered from DB, where protection measures has been put in place in previous PRs). Let's assume the constructor for statusCode and errorCode is the
In the case of variables, we have to check if the varible is field using "%s". (*) In the case of having several constructors (I don't remember now), the same procedure could be applied to all them. |
In either case, don't forget we already html-escape all output. |
I was testing with a wrong branch. I have checkout to feature/619_escaped_output and test again:
It seems that even in the case of input "bypass" we are protected by httml escape in any case. Thus it seems we don't need any additional modification and the code is ok now. |
It gets confirmed that no extra modifications are needed to protect CB from script injection. However, remaining "clean up" works has been moved to tech debt issue #661 |
Let's consider the following set of forbidden characters:
Two behaviors have to be implemented in Orion CB, one related to requests and other related to responses.
Regarding requests, the CB must avoid these characters being used in some "protected" fields in requests. In particular:
(Taking into account the large number of fields, maybe it makes sense to adopt a "global protection" approach, protecting every field).
If the user attempts to use any forbidden character, the broker should return a "400 Bad Request" NGSI error, explaining the details of the problem (but without citing the offending characters?), e.g. "Forbidden characters in field X, please check Orion documentation". As any other bad input problem, this should be logged with the proper LM_W.
Special note regarding XML: the checking has to be done after "XML entities" translation, i.e. it is legal that a client sends for instance
<contextValue>H&M shop</contextValue>
as it translates as "H&M". Thus, the checking routine should check "H&M" not "H&M" because, in the second case, it will raise a bad input and disable any possibily of XML users to use some characters forbidden in XML but that aren't part of the set defined above (e.g. "&"). I guess that the XML parser deals with translation, thus probably intercepting the fields as offered by the XML parsing library will work.Regarding responses, CB should process the resulting payload string after rendering and just before passing it to the HTTP library to send the response in order to escape any forbidden characters. Note this is necessary because of two reasons: 1) some user with DB privileges could have introduced information at DB layer (thus not protected by the above behavior regarding requests) using forbidden characters, 2) in the case of some payload response pieces that are "bypassed" from the request in special cases (e.g. "Service not recognized", which literally uses the URL provided by the user in the request).
We will use the
URL encodingHTML encoding, thus the translation for each one of the forbidden characters is the following:(Reference: http://www.asciitable.com/)
The text was updated successfully, but these errors were encountered: