-
Notifications
You must be signed in to change notification settings - Fork 6
Conversation
…docker compose env file is not supported
I'd suggest to use wdyt? |
Hm, I'm not sure. Using quote would introduce - obviously - quotes which we are trying to avoid.
If you execute it you will notice it starts and ends with single quotes. Docker won't parse those quotes. I can think of just a single character the quote may defend us against - new line (\n) and/or maybe carriage return (\r). User could paste following as graffiti: As you can see this would allow user to insert arbitrary env variables. I don't think it is possible to set graffiti with newline inside using dialog interface, but may be possible using web interface (I haven't tested it). However, the user is already root, so he/she won't gain anything from expliting this vulnerability. But maybe somewhere in the future you decide to allow non-root users to set graffiti? Here is PoC of vulnerability with fix implemented. Just run this playbook and compare secure.env and insecure.env files.
Basically the fix makes sure we use only the first line of graffiti text. Do you have in mind other special characters we should quote? |
I think all special characters should be escaped, this includes @gbayasgalan do you have some input? You had this issue before with something else afair. |
Why do you want to escape any of those characters? What will happen if they are not escaped? |
Yes, I had issue with a input which is parameter of bash script. In my case single quote {{ ansible | quote }} worked, any character inside 'single quote' is taken as input |
In this case (setting graffiti for Lighthouse) the data flow looks like this:
Current solution is to escape data at point 3. It is like escaping data before writing it to database. From my experience, the widely accepted good practice is to write raw data to database, and take care escaping it later, when it is used. For example when it is displayed on html page as a text it should be escaped to not include html tags. When it becomes part of javascript string, html tags are ok, but quotes has to be escaped. You never know how data should be escaped, therefore it's better to store it in the raw form. And .env used by Docker compose looks like a database, in which such a raw form could be stored. Of course with the exception of special handling of newlines. I think the user input should be sanitized according to requirements of the channel it is being transmitted in. What do you think? |
I agree and it makes sense to escape as late as possible. Interesting enough, some special characters already need attention in the To me the more time I look at it the more complex it gets. |
Set graffiti for Lighthouse without double quotes because quoting in docker compose env file is not supported.
From Docker Compose docs:
"The value of VAL is used as is and not modified at all. For example if the value is surrounded by quotes (as is often the case of shell variables), the quotes are included in the value passed to Compose."
https://docs.docker.com/compose/compose-file/compose-file-v3/