Skip to content

Commit a3fbc3c

Browse files
committed
fix ResponseBody Class issues
1 parent dbf01a9 commit a3fbc3c

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

go/ql/lib/semmle/go/frameworks/Fasthttp.qll

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,47 +81,42 @@ module Fasthttp {
8181
}
8282
}
8383

84-
private predicate responseBodyWriterResult(DataFlow::Node src) {
85-
exists(Method responseBodyWriter |
86-
responseBodyWriter.hasQualifiedName(packagePath(), "Response", "BodyWriter") and
87-
src = responseBodyWriter.getACall().getResult(0)
88-
)
89-
}
90-
91-
private module ResponseBodyWriterFlow = DataFlow::SimpleGlobal<responseBodyWriterResult/1>;
92-
9384
private class ResponseBody extends Http::ResponseBody::Range {
9485
DataFlow::MethodCallNode call;
95-
string methodName;
9686

9787
ResponseBody() {
9888
exists(Method m |
99-
m.hasQualifiedName(packagePath(), "Response", methodName) and
89+
m.hasQualifiedName(packagePath(), "Response",
90+
[
91+
"AppendBody", "AppendBodyString", "SetBody", "SetBodyRaw", "SetBodyStream",
92+
"SetBodyString", "Success", "SuccessString"
93+
]) and
10094
call = m.getACall() and
10195
this = call.getArgument(0)
10296
or
10397
m.hasQualifiedName(packagePath(), "RequestCtx", ["Success", "SuccessString"]) and
10498
call = m.getACall() and
10599
this = call.getArgument(1)
106-
) and
107-
methodName =
108-
[
109-
"AppendBody", "AppendBodyString", "SetBody", "SetBodyRaw", "SetBodyStream",
110-
"SetBodyString", "Success", "SuccessString"
111-
]
100+
)
101+
or
102+
exists(Method responseBodyWriter, DataFlow::CallNode writerCall |
103+
responseBodyWriter.hasQualifiedName(packagePath(), "Response", "BodyWriter") and
104+
call = responseBodyWriter.getACall() and
105+
writerCall = any(Method write | write.hasQualifiedName("io", "Writer", "Write")).getACall() and
106+
this = writerCall.getArgument(0) and
107+
DataFlow::localFlow(call.getResult(0), writerCall.getReceiver())
108+
)
112109
or
113-
exists(Method write, DataFlow::CallNode writeCall |
114-
write.hasQualifiedName("io", "Writer", "Write") and
115-
writeCall = write.getACall() and
116-
ResponseBodyWriterFlow::flowsTo(writeCall.getReceiver()) and
117-
this = writeCall.getArgument(0)
118-
) and
119-
methodName = "BodyWriter"
110+
exists(Method responseBodyWriter, DataFlow::CallNode writerCall |
111+
responseBodyWriter.hasQualifiedName(packagePath(), "Response", "BodyWriter") and
112+
call = responseBodyWriter.getACall() and
113+
writerCall = any(Function fprintf | fprintf.hasQualifiedName("fmt", "Fprintf")).getACall() and
114+
this = writerCall.getSyntacticArgument(any(int i | i > 1)) and
115+
DataFlow::localFlow(call.getResult(0), writerCall.getArgument(0))
116+
)
120117
}
121118

122119
override Http::ResponseWriter getResponseWriter() { result.getANode() = call.getReceiver() }
123-
124-
override string getAContentType() { result = super.getAContentType() }
125120
}
126121

127122
/**

go/ql/test/library-tests/semmle/go/frameworks/Fasthttp/fasthttp.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ func fasthttpServer() {
180180
requestCtx.Response.AppendBodyString(userInput) // $ XssSink=userInput
181181
rspWriter := requestCtx.Response.BodyWriter()
182182
rspWriter.Write(userInputByte) // $ XssSink=userInputByte
183+
fmt.Fprintf(rspWriter, "%s", userInputByte) // $ XssSink=userInputByte
183184
requestCtx.Response.SetBody(userInputByte) // $ XssSink=userInputByte
184185
requestCtx.Response.SetBodyString(userInput) // $ XssSink=userInput
185186
requestCtx.Response.SetBodyRaw(userInputByte) // $ XssSink=userInputByte

0 commit comments

Comments
 (0)