-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
Prevent CSV injection attacks #662
Conversation
lib/phlex/csv.rb
Outdated
@@ -82,9 +82,13 @@ def render(renderable) | |||
end | |||
|
|||
def escape(value) | |||
value = value.to_s | |||
value = value.to_s.dup | |||
value.strip! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be optional. Perhaps you should be able to define def strip_values? = false
or something like that.
def collection_yielder(record) | ||
def yielder(record) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to the main purpose of this PR, I think I prefer yielder
for this method, since it's not really yielding the collection, it's really yielding a single item in the collection.
lib/phlex/csv.rb
Outdated
unless prevent_csv_injection? == true || prevent_csv_injection? == false | ||
raise "You must define `prevent_csv_injection?` on #{self.class.inspect}, returning `true` or `false`. See https://owasp.org/www-community/attacks/CSV_Injection" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By settings prevent_csv_injection?
to nil
by default, we can force the developer to make an informed decision upfront by raising here. The developer must choose whether to enable or disable the protection, and they have an opportunity to learn about the risk on owasp.org.
This reverts commit c48c915.
2a71eb8
to
8f22b1d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for battling this out with me 😇
Closes #661 and also closes #659.
Todo