Add combinator to include label in comments with generated SQL.#124
Add combinator to include label in comments with generated SQL.#124tomjaguarpaw merged 3 commits intotomjaguarpaw:masterfrom
Conversation
a0a465d to
7411166
Compare
|
Hi, thanks for this. Sorry for not replying sooner. I didn't see the notification. In general, if I take a long time to respond to a PR or bug report please send a message to get my attention. Looks like it needs to be rebased, but other than that it looks like a good idea. By the way, this will not work. It will replace |
|
No problem, I figured you were busy and didn't want to bother you with my impatience. Regarding |
|
I'll leave it up to you how to deal with the comments but I think there should be some tests to ensure it can't be used for SQL injections. Will a version using Don't worry about bothering me. If you think I've missed something please let me know. Even if I'm too busy I intend to reply to say so explicitly. |
|
How should I set up these tests? I can annotate some queries with bad labels and check that they still run, but I'm not sure if that tests the right thing. |
A label like "----" would defuse to "- -- -" and still contain a comment. This is prevented by more whitespace to make sure the characters will never touch after replacing.
|
I would only test the quoting function, but how you do that is a good question ... |
|
So in summary, yes this looks really good and will improve Opaleye. If you can reassure me about quoting the comments I'll merge it. Why is |
|
You're right, only '*/' will terminate the comment that Opaleye inserts before the label. But, SQL injections might use Therefore, defusing any comment character seems like a good idea to me. Inserting whitespace defuses the comment and by padding it with whitespace it's impossible to create new comment characters from the original, like in your earlier example. |
|
Could you specify precisely how an attacker would do that? When you have Anyway, I don't mind defusing |
|
You're right, it will be ignored. I can't come up with an evil example using Note that we do need to defuse |
Add combinator to include label in comments with generated SQL.
|
This is a useful patch, very well written to keep it in the overall style of the library. Very nice! |
|
Thanks, happy to contribute! |
This fixes #123.
I'm not sure about the implementation of
defuseComments, maybe you have some wishes on how to do that? The label should be cleaned up so that it cannot be used for SQL injections.Also, I looked at this with @hesselink and he suggested using the
CallStackimplicit parameter from GHC 7.10 to automatically insert locations into labels for queries. We have implemented this at Silk and it works out pretty well! We'll actually use this once we upgrade our stack to GHC 7.10. Maybe Opaleye can use this approach too to include labels automatically?