Skip to content
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

Escaping question #3

Closed
ianshefferman opened this issue Jul 21, 2014 · 2 comments
Closed

Escaping question #3

ianshefferman opened this issue Jul 21, 2014 · 2 comments

Comments

@ianshefferman
Copy link

I'm not an expert at PostgreSQL, but shouldn't backslashes also be doubled too, to prevent an attacker from escaping '' with \''?

return "'#{(val\gsub "'", "''")}'"

@leafo
Copy link
Owner

leafo commented Jul 21, 2014

Modern versions of postgres don't treat backslash as an escape character in regular string literals:

leafo=# select '\''hello';
 ?column? 
----------
 \'hello
(1 row)

leafo=# select 'hello\nhello';
   ?column?   
--------------
 hello\nhello
(1 row)

From the documentation:

If the configuration parameter standard_conforming_strings is off, then PostgreSQL recognizes backslash escapes in both regular and escape string constants. However, as of PostgreSQL 9.1, the default is on, meaning that backslash escapes are recognized only in escape string constants.

I do not mention anywhere that 9.1 or above should be used, and that the default settings should not be changed though.

@ianshefferman
Copy link
Author

Thanks, that's pretty much what I figured. I'll be sure to use the most up-to-date version of PostgreSQL in my projects. I suppose it may be worthwhile to mention in the README that this library is designed for 9.1+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants