Skip to content

Commit 130d93d

Browse files
committed
Ruby: Make HttpToFileAccess more specific
Only consider sources from HTTP requests, rather than any remote flow source.
1 parent fac1738 commit 130d93d

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

ruby/ql/lib/codeql/ruby/Concepts.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ module HTTP {
298298
* extend `RequestInputAccess::Range` instead.
299299
*/
300300
class RequestInputAccess extends DataFlow::Node instanceof RequestInputAccess::Range {
301+
/**
302+
* Gets a string that describes the type of this input.
303+
*
304+
* This is typically the name of the method that gives rise to this input.
305+
*/
301306
string getSourceType() { result = super.getSourceType() }
302307
}
303308

@@ -310,6 +315,11 @@ module HTTP {
310315
* extend `RequestInputAccess` instead.
311316
*/
312317
abstract class Range extends DataFlow::Node {
318+
/**
319+
* Gets a string that describes the type of this input.
320+
*
321+
* This is typically the name of the method that gives rise to this input.
322+
*/
313323
abstract string getSourceType();
314324
}
315325
}

ruby/ql/lib/codeql/ruby/security/HttpToFileAccessCustomizations.qll

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import codeql.ruby.DataFlow
99
import codeql.ruby.dataflow.RemoteFlowSources
1010
import codeql.ruby.Concepts
1111

12+
/**
13+
* Provides default sources, sinks and sanitizers for reasoning about
14+
* writing user-controlled data to files, as well as extension points
15+
* for adding your own.
16+
*/
1217
module HttpToFileAccess {
1318
/**
1419
* A data flow source for writing user-controlled data to files.
@@ -25,9 +30,15 @@ module HttpToFileAccess {
2530
*/
2631
abstract class Sanitizer extends DataFlow::Node { }
2732

28-
/** A source of remote user input, considered as a flow source for writing user-controlled data to files. */
29-
class RemoteFlowSourceAsSource extends Source {
30-
RemoteFlowSourceAsSource() { this instanceof RemoteFlowSource }
33+
/**
34+
* An access to a user-controlled HTTP request input, considered as a flow source for writing user-controlled data to files
35+
*/
36+
private class RequestInputAccessAsSource extends Source instanceof HTTP::Server::RequestInputAccess {
37+
}
38+
39+
/** A response from an outgoing HTTP request, considered as a flow source for writing user-controlled data to files. */
40+
private class HttpResponseAsSource extends Source {
41+
HttpResponseAsSource() { this = any(HTTP::Client::Request r).getResponseBody() }
3142
}
3243

3344
/** A sink that represents file access method (write, append) argument */

0 commit comments

Comments
 (0)