Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8962054

Browse filesBrowse files
committed
Merge branch 'main' into accept-test-output-example
2 parents c581131 + edfe2d7 commit 8962054
Copy full SHA for 8962054

File tree

6 files changed

+223
-312
lines changed
Filter options

6 files changed

+223
-312
lines changed

‎go/ql/lib/semmle/go/security/Xss.qll

Copy file name to clipboardExpand all lines: go/ql/lib/semmle/go/security/Xss.qll
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,20 @@ module SharedXss {
127127
)
128128
}
129129
}
130+
131+
/**
132+
* A `Template` from `html/template` will HTML-escape data automatically
133+
* and therefore acts as a sanitizer for XSS vulnerabilities.
134+
*/
135+
class HtmlTemplateSanitizer extends Sanitizer, DataFlow::Node {
136+
HtmlTemplateSanitizer() {
137+
exists(Method m, DataFlow::CallNode call | m = call.getCall().getTarget() |
138+
m.hasQualifiedName("html/template", "Template", "ExecuteTemplate") and
139+
call.getArgument(2) = this
140+
or
141+
m.hasQualifiedName("html/template", "Template", "Execute") and
142+
call.getArgument(1) = this
143+
)
144+
}
145+
}
130146
}

‎go/ql/src/experimental/CWE-79/HTMLTemplateEscapingPassthrough.ql

Copy file name to clipboardExpand all lines: go/ql/src/experimental/CWE-79/HTMLTemplateEscapingPassthrough.ql
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ class FlowConfFromUntrustedToPassthroughTypeConversion extends TaintTracking::Co
6464
}
6565

6666
override predicate isSink(DataFlow::Node sink) { isSinkToPassthroughType(sink, dstTypeName) }
67+
68+
override predicate isSanitizer(DataFlow::Node sanitizer) {
69+
sanitizer instanceof SharedXss::Sanitizer or sanitizer.getType() instanceof NumericType
70+
}
6771
}
6872

6973
/**
@@ -100,7 +104,7 @@ class FlowConfPassthroughTypeConversionToTemplateExecutionCall extends TaintTrac
100104
PassthroughTypeName getDstTypeName() { result = dstTypeName }
101105

102106
override predicate isSource(DataFlow::Node source) {
103-
isSourceConversionToPassthroughType(source, _)
107+
isSourceConversionToPassthroughType(source, dstTypeName)
104108
}
105109

106110
private predicate isSourceConversionToPassthroughType(
@@ -141,10 +145,6 @@ class FlowConfFromUntrustedToTemplateExecutionCall extends TaintTracking::Config
141145
override predicate isSource(DataFlow::Node source) { source instanceof UntrustedFlowSource }
142146

143147
override predicate isSink(DataFlow::Node sink) { isSinkToTemplateExec(sink, _) }
144-
145-
override predicate isSanitizer(DataFlow::Node sanitizer) {
146-
sanitizer instanceof SharedXss::Sanitizer or sanitizer.getType() instanceof NumericType
147-
}
148148
}
149149

150150
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.