File tree Expand file tree Collapse file tree 5 files changed +28
-0
lines changed
lib/codeql/ruby/frameworks
src/experimental/template-injection/examples
test/query-tests/experimental/TemplateInjection Expand file tree Collapse file tree 5 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -400,3 +400,19 @@ private class AccessLocalsKeySummary extends SummarizedCallable {
400
400
preservesValue = true
401
401
}
402
402
}
403
+
404
+ /** A call to `render inline: foo`, considered as a ERB template rendering. */
405
+ private class RailsTemplateRendering extends TemplateRendering:: Range , DataFlow:: CallNode {
406
+ private DataFlow:: Node template ;
407
+
408
+ RailsTemplateRendering ( ) {
409
+ (
410
+ this .asExpr ( ) .getExpr ( ) instanceof Rails:: RenderCall
411
+ or
412
+ this .asExpr ( ) .getExpr ( ) instanceof Rails:: RenderToCall
413
+ ) and
414
+ template = this .getKeywordArgument ( "inline" )
415
+ }
416
+
417
+ override DataFlow:: Node getTemplate ( ) { result = template }
418
+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ def some_request_handler
9
9
<h2>Hello %s </h2></body></html>
10
10
" % name
11
11
template = ERB . new ( html_text ) . result ( binding )
12
+ render inline : html_text
12
13
end
13
14
end
14
15
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ def some_request_handler
9
9
<h2>Hello <%= name %> </h2></body></html>
10
10
"
11
11
template = ERB . new ( html_text ) . result ( binding )
12
+ render inline : html_text
12
13
end
13
14
end
14
15
Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ def some_request_handler
14
14
# where name is unsanitized
15
15
template = ERB . new ( bad_text ) . result ( binding )
16
16
17
+ # BAD: user input is evaluated
18
+ # where name is unsanitized
19
+ render inline : bad_text
20
+
17
21
# Template with the source
18
22
good_text = "
19
23
<!DOCTYPE html><html><body>
@@ -22,6 +26,9 @@ def some_request_handler
22
26
23
27
# GOOD: user input is not evaluated
24
28
template2 = ERB . new ( good_text ) . result ( binding )
29
+
30
+ # GOOD: user input is not evaluated
31
+ render inline : good_text
25
32
end
26
33
end
27
34
Original file line number Diff line number Diff line change 4
4
| ErbInjection.rb:5:12:5:17 | call to params | ErbInjection.rb:5:12:5:24 | ...[...] |
5
5
| ErbInjection.rb:5:12:5:24 | ...[...] | ErbInjection.rb:5:5:5:8 | name |
6
6
| ErbInjection.rb:8:5:8:12 | bad_text | ErbInjection.rb:15:24:15:31 | bad_text |
7
+ | ErbInjection.rb:8:5:8:12 | bad_text | ErbInjection.rb:19:20:19:27 | bad_text |
7
8
| ErbInjection.rb:8:16:11:14 | ... % ... | ErbInjection.rb:8:5:8:12 | bad_text |
8
9
| ErbInjection.rb:11:11:11:14 | name | ErbInjection.rb:8:16:11:14 | ... % ... |
9
10
| SlimInjection.rb:5:5:5:8 | name | SlimInjection.rb:8:5:8:12 | bad_text |
23
24
| ErbInjection.rb:8:16:11:14 | ... % ... | semmle.label | ... % ... |
24
25
| ErbInjection.rb:11:11:11:14 | name | semmle.label | name |
25
26
| ErbInjection.rb:15:24:15:31 | bad_text | semmle.label | bad_text |
27
+ | ErbInjection.rb:19:20:19:27 | bad_text | semmle.label | bad_text |
26
28
| SlimInjection.rb:5:5:5:8 | name | semmle.label | name |
27
29
| SlimInjection.rb:5:12:5:17 | call to params | semmle.label | call to params |
28
30
| SlimInjection.rb:5:12:5:24 | ...[...] | semmle.label | ...[...] |
35
37
subpaths
36
38
#select
37
39
| ErbInjection.rb:15:24:15:31 | bad_text | ErbInjection.rb:5:12:5:17 | call to params | ErbInjection.rb:15:24:15:31 | bad_text | This template depends on a $@. | ErbInjection.rb:5:12:5:17 | call to params | user-provided value |
40
+ | ErbInjection.rb:19:20:19:27 | bad_text | ErbInjection.rb:5:12:5:17 | call to params | ErbInjection.rb:19:20:19:27 | bad_text | This template depends on a $@. | ErbInjection.rb:5:12:5:17 | call to params | user-provided value |
38
41
| SlimInjection.rb:14:25:14:32 | bad_text | SlimInjection.rb:5:12:5:17 | call to params | SlimInjection.rb:14:25:14:32 | bad_text | This template depends on a $@. | SlimInjection.rb:5:12:5:17 | call to params | user-provided value |
39
42
| SlimInjection.rb:23:25:23:33 | bad2_text | SlimInjection.rb:5:12:5:17 | call to params | SlimInjection.rb:23:25:23:33 | bad2_text | This template depends on a $@. | SlimInjection.rb:5:12:5:17 | call to params | user-provided value |
You can’t perform that action at this time.
0 commit comments