Skip to content

Commit 9dedb05

Browse files
authored
Merge pull request #312 from github/rb/stored-xss-1
Implement `rb/stored-xss` query
2 parents 2a32b59 + 16ab4da commit 9dedb05

32 files changed

+5287
-80
lines changed

ql/lib/codeql/ruby/Concepts.qll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,3 +538,32 @@ module XmlParserCall {
538538
abstract predicate externalEntitiesEnabled();
539539
}
540540
}
541+
542+
/**
543+
* A data-flow node that may represent a database object in an ORM system.
544+
*
545+
* Extend this class to refine existing API models. If you want to model new APIs,
546+
* extend `OrmInstantiation::Range` instead.
547+
*/
548+
class OrmInstantiation extends DataFlow::Node instanceof OrmInstantiation::Range {
549+
/** Holds if a call to `methodName` on this instance may return a field of this ORM object. */
550+
bindingset[methodName]
551+
predicate methodCallMayAccessField(string methodName) {
552+
super.methodCallMayAccessField(methodName)
553+
}
554+
}
555+
556+
/** Provides a class for modeling new ORM object instantiation APIs. */
557+
module OrmInstantiation {
558+
/**
559+
* A data-flow node that may represent a database object in an ORM system.
560+
*
561+
* Extend this class to model new APIs. If you want to refine existing API models,
562+
* extend `OrmInstantiation` instead.
563+
*/
564+
abstract class Range extends DataFlow::Node {
565+
/** Holds if a call to `methodName` on this instance may return a field of this ORM object. */
566+
bindingset[methodName]
567+
abstract predicate methodCallMayAccessField(string methodName);
568+
}
569+
}

ql/lib/codeql/ruby/DataFlow2.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Provides classes for performing local (intra-procedural) and
3+
* global (inter-procedural) data flow analyses.
4+
*/
5+
module DataFlow2 {
6+
import codeql.ruby.dataflow.internal.DataFlowImpl2
7+
}

ql/lib/codeql/ruby/ast/Constant.qll

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,35 @@ class ConstantWriteAccess extends ConstantAccess {
166166
}
167167

168168
override string getAPrimaryQlClass() { result = "ConstantWriteAccess" }
169+
170+
/**
171+
* Gets the fully qualified name for this constant, based on the context in
172+
* which it is defined.
173+
*
174+
* For example, given
175+
* ```rb
176+
* module Foo
177+
* module Bar
178+
* class Baz
179+
* end
180+
* end
181+
* CONST_A = "a"
182+
* end
183+
* ```
184+
*
185+
* the constant `Baz` has the fully qualified name `Foo::Bar::Baz`, and
186+
* `CONST_A` has the fully qualified name `Foo::CONST_A`.
187+
*/
188+
string getQualifiedName() {
189+
/* get the qualified name for the parent module, then append w */
190+
exists(ConstantWriteAccess parent | parent = this.getEnclosingModule() |
191+
result = parent.getQualifiedName() + "::" + this.getName()
192+
)
193+
or
194+
/* base case - there's no parent module */
195+
not exists(ConstantWriteAccess parent | parent = this.getEnclosingModule()) and
196+
result = this.getName()
197+
}
169198
}
170199

171200
/**

0 commit comments

Comments
 (0)