Skip to content

Commit 21e31a4

Browse files
authored
Merge pull request #283 from github/file-system-sources
Start modelling some file system access concepts
2 parents dd31473 + b769aa6 commit 21e31a4

File tree

9 files changed

+567
-61
lines changed

9 files changed

+567
-61
lines changed

ql/lib/codeql/ruby/Concepts.qll

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,98 @@ module SqlExecution {
3636
}
3737
}
3838

39+
/**
40+
* A data flow node that performs a file system access, including reading and writing data,
41+
* creating and deleting files and folders, checking and updating permissions, and so on.
42+
*
43+
* Extend this class to refine existing API models. If you want to model new APIs,
44+
* extend `FileSystemAccess::Range` instead.
45+
*/
46+
class FileSystemAccess extends DataFlow::Node instanceof FileSystemAccess::Range {
47+
/** Gets an argument to this file system access that is interpreted as a path. */
48+
DataFlow::Node getAPathArgument() { result = super.getAPathArgument() }
49+
}
50+
51+
/** Provides a class for modeling new file system access APIs. */
52+
module FileSystemAccess {
53+
/**
54+
* A data-flow node that performs a file system access, including reading and writing data,
55+
* creating and deleting files and folders, checking and updating permissions, and so on.
56+
*
57+
* Extend this class to model new APIs. If you want to refine existing API models,
58+
* extend `FileSystemAccess` instead.
59+
*/
60+
abstract class Range extends DataFlow::Node {
61+
/** Gets an argument to this file system access that is interpreted as a path. */
62+
abstract DataFlow::Node getAPathArgument();
63+
}
64+
}
65+
66+
/**
67+
* A data flow node that reads data from the file system.
68+
*
69+
* Extend this class to refine existing API models. If you want to model new APIs,
70+
* extend `FileSystemReadAccess::Range` instead.
71+
*/
72+
class FileSystemReadAccess extends FileSystemAccess instanceof FileSystemReadAccess::Range {
73+
/**
74+
* Gets a node that represents data read from the file system access.
75+
*/
76+
DataFlow::Node getADataNode() { result = FileSystemReadAccess::Range.super.getADataNode() }
77+
}
78+
79+
/** Provides a class for modeling new file system reads. */
80+
module FileSystemReadAccess {
81+
/**
82+
* A data flow node that reads data from the file system.
83+
*
84+
* Extend this class to model new APIs. If you want to refine existing API models,
85+
* extend `FileSystemReadAccess` instead.
86+
*/
87+
abstract class Range extends FileSystemAccess::Range {
88+
/**
89+
* Gets a node that represents data read from the file system.
90+
*/
91+
abstract DataFlow::Node getADataNode();
92+
}
93+
}
94+
95+
/**
96+
* A data flow node that sets the permissions for one or more files.
97+
*
98+
* Extend this class to refine existing API models. If you want to model new APIs,
99+
* extend `FileSystemPermissionModification::Range` instead.
100+
*/
101+
class FileSystemPermissionModification extends DataFlow::Node instanceof FileSystemPermissionModification::Range {
102+
/**
103+
* Gets an argument to this permission modification that is interpreted as a
104+
* set of permissions.
105+
*/
106+
DataFlow::Node getAPermissionNode() { result = super.getAPermissionNode() }
107+
}
108+
109+
/** Provides a class for modeling new file system permission modifications. */
110+
module FileSystemPermissionModification {
111+
/**
112+
* A data-flow node that sets permissions for a one or more files.
113+
*
114+
* Extend this class to model new APIs. If you want to refine existing API models,
115+
* extend `FileSystemPermissionModification` instead.
116+
*/
117+
abstract class Range extends DataFlow::Node {
118+
/**
119+
* Gets an argument to this permission modification that is interpreted as a
120+
* set of permissions.
121+
*/
122+
abstract DataFlow::Node getAPermissionNode();
123+
}
124+
}
125+
126+
/**
127+
* A data flow node that contains a file name or an array of file names from the local file system.
128+
*/
129+
abstract class FileNameSource extends DataFlow::Node { }
130+
39131
/**
40132
* A data-flow node that escapes meta-characters, which could be used to prevent
41133
* injection attacks.

ql/lib/codeql/ruby/Frameworks.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ private import codeql.ruby.frameworks.ActionController
66
private import codeql.ruby.frameworks.ActiveRecord
77
private import codeql.ruby.frameworks.ActionView
88
private import codeql.ruby.frameworks.StandardLibrary
9+
private import codeql.ruby.frameworks.Files

0 commit comments

Comments
 (0)