Add cop that detects usage of dangerous IO method calls
In !82689 (e097465b) an MR introduced code that used IO.foreach. Similar to open (which is already blocked by this cop), most IO methods have a feature to spawn a subshell if the parameter starts with a |.
Based on the documentation the dangerous methods appear to be
IO.binreadIO.foreachIO.readIO.readlinesIO.write
$ ruby -e 'puts IO.foreach("|echo arbitrary command execution").to_a'
arbitrary command execution
Usage of those methods is extremely dangerous and they all have a safer alternatives in the File class. For example:
$ ruby -e 'puts File.foreach("|echo arbitrary command execution").to_a'
Traceback (most recent call last):
3: from -e:1:in `<main>'
2: from -e:1:in `to_a'
1: from -e:1:in `each'
-e:1:in `foreach': No such file or directory @ rb_sysopen - |echo arbitrary command execution (Errno::ENOENT)
We should have a cop that blocks those methods and breaks the build so we don't have to rely completely on the vigilance of the reviewers.
Edited by Dominic Couture