Skip to content

Commit 257506b

Browse files
owen-mcmbg
authored andcommitted
Fix alias use in HTML template escaping passthrough
1 parent 6d44f57 commit 257506b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

go/ql/lib/semmle/go/Types.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,17 @@ class AliasType extends @typealias, CompositeType {
10151015
override Type getUnderlyingType() { result = this.getRhs().getUnderlyingType() }
10161016
}
10171017

1018+
/**
1019+
* Gets the non-alias type at the end of the alias chain starting at `t`.
1020+
*
1021+
* If `t` is not an alias type then `result` is `t`.
1022+
*/
1023+
Type unalias(Type t) {
1024+
not t instanceof AliasType and result = t
1025+
or
1026+
result = unalias(t.(AliasType).getRhs())
1027+
}
1028+
10181029
/**
10191030
* A type that implements the builtin interface `error`.
10201031
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module UntrustedToPassthroughTypeConversionConfig implements DataFlow::ConfigSig
4141
additional predicate isSinkToPassthroughType(DataFlow::TypeCastNode sink, PassthroughTypeName name) {
4242
exists(Type typ |
4343
typ = sink.getResultType() and
44-
typ.getUnderlyingType*().hasQualifiedName("html/template", name)
44+
unalias(typ).hasQualifiedName("html/template", name)
4545
)
4646
}
4747

@@ -80,7 +80,7 @@ module PassthroughTypeConversionToTemplateExecutionCallConfig implements DataFlo
8080
) {
8181
exists(Type typ |
8282
typ = source.getResultType() and
83-
typ.getUnderlyingType*().hasQualifiedName("html/template", name)
83+
unalias(typ).hasQualifiedName("html/template", name)
8484
)
8585
}
8686

0 commit comments

Comments
 (0)