Skip to content

Commit

Permalink
Bottle
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwstubbs committed Sep 3, 2024
1 parent 326eb69 commit 581e7f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 42 deletions.
30 changes: 9 additions & 21 deletions python/ql/lib/semmle/python/frameworks/Bottle.qll
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Provides classes modeling security-relevant aspects of the `bottle` PyPI package.
* See https://www.tornadoweb.org/en/stable/.
* See https://bottlepy.org/docs/dev/.
*/

private import python
Expand All @@ -14,28 +14,24 @@ private import semmle.python.frameworks.internal.InstanceTaintStepsHelper
* INTERNAL: Do not use.
*
* Provides models for the `bottle` PyPI package.
* See https://www.tornadoweb.org/en/stable/.
* See https://bottlepy.org/docs/dev/.
*/
module Bottle {
module BottleModule {

Check warning on line 20 in python/ql/lib/semmle/python/frameworks/Bottle.qll

View workflow job for this annotation

GitHub Actions / qldoc

Missing QLdoc for module Bottle::Bottle::BottleModule
API::Node bottle() { result = API::moduleImport("bottle") }

Check warning on line 21 in python/ql/lib/semmle/python/frameworks/Bottle.qll

View workflow job for this annotation

GitHub Actions / qldoc

Missing QLdoc for classless-predicate Bottle::Bottle::BottleModule::bottle/0

module Response {

Check warning on line 23 in python/ql/lib/semmle/python/frameworks/Bottle.qll

View workflow job for this annotation

GitHub Actions / qldoc

Missing QLdoc for module Bottle::Bottle::BottleModule::Response
API::Node response() {
result = bottle().getMember("response")
//or
//result = ModelOutput::getATypeNode("tornado.web.RequestHandler~Subclass").getASubclass*()
}
API::Node response() { result = bottle().getMember("response") }

Check warning on line 24 in python/ql/lib/semmle/python/frameworks/Bottle.qll

View workflow job for this annotation

GitHub Actions / qldoc

Missing QLdoc for classless-predicate Bottle::Bottle::BottleModule::Response::response/0

/**
* A call to the `bottle.web.RequestHandler.set_header` method.
* A call to the `bottle.web.RequestHandler.set_header` or `bottle.web.RequestHandler.add_header` method.
*
* See https://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.set_header
* See https://bottlepy.org/docs/dev/api.html#bottle.BaseResponse.set_header
*/
class BottleRequestHandlerSetHeaderCall extends Http::Server::ResponseHeaderWrite::Range,
class BottleResponseHandlerSetHeaderCall extends Http::Server::ResponseHeaderWrite::Range,
DataFlow::MethodCallNode
{
BottleRequestHandlerSetHeaderCall() {
BottleResponseHandlerSetHeaderCall() {
this = response().getMember(["set_header", "add_header"]).getACall()
}

Expand All @@ -58,15 +54,13 @@ module Bottle {
private class Request extends RemoteFlowSource::Range {
Request() { this = request().asSource() }

//or
//result = ModelOutput::getATypeNode("tornado.web.RequestHandler~Subclass").getASubclass*()
override string getSourceType() { result = "bottle.request" }
}

/**
* Taint propagation for `bottle.request`.
*
* See https://flask.palletsprojects.com/en/1.1.x/api/#flask.Request
* See https://bottlepy.org/docs/dev/api.html#bottle.request
*/
private class InstanceTaintSteps extends InstanceTaintStepsHelper {
InstanceTaintSteps() { this = "bottle.request" }
Expand All @@ -86,11 +80,7 @@ module Bottle {
}

module Header {

Check warning on line 82 in python/ql/lib/semmle/python/frameworks/Bottle.qll

View workflow job for this annotation

GitHub Actions / qldoc

Missing QLdoc for module Bottle::Bottle::BottleModule::Response::Header
API::Node instance() {
result = bottle().getMember("response").getMember("headers")
//or
//result = ModelOutput::getATypeNode("tornado.web.RequestHandler~Subclass").getASubclass*()
}
API::Node instance() { result = bottle().getMember("response").getMember("headers") }

Check warning on line 83 in python/ql/lib/semmle/python/frameworks/Bottle.qll

View workflow job for this annotation

GitHub Actions / qldoc

Missing QLdoc for classless-predicate Bottle::Bottle::BottleModule::Response::Header::instance/0

/** A dict-like write to a response header. */
class HeaderWriteSubscript extends Http::Server::ResponseHeaderWrite::Range, DataFlow::Node {
Expand All @@ -105,12 +95,10 @@ module Bottle {
)
}

//name = instance().getASubscript().getIndex().asSink()
override DataFlow::Node getNameArg() { result = name.asSink() }

override DataFlow::Node getValueArg() { result = value.asSink() }

// TODO: These checks perhaps could be made more precise.
override predicate nameAllowsNewline() { none() }

override predicate valueAllowsNewline() { none() }
Expand Down
21 changes: 0 additions & 21 deletions python/ql/lib/semmle/python/frameworks/Tornado.qll
Original file line number Diff line number Diff line change
Expand Up @@ -605,25 +605,4 @@ module Tornado {

override DataFlow::Node getValueArg() { result in [this.getArg(1), this.getArgByName("value")] }
}

/**
* A call to the `tornado.web.RequestHandler.set_header` method.
*
* See https://www.tornadoweb.org/en/stable/web.html#tornado.web.RequestHandler.set_header
*/
class TornadoRequestHandlerSetHeaderCall extends Http::Server::ResponseHeaderWrite::Range,
DataFlow::MethodCallNode
{
TornadoRequestHandlerSetHeaderCall() {
this.calls(TornadoModule::Web::RequestHandler::instance(), "set_header")
}

override DataFlow::Node getNameArg() { result in [this.getArg(0), this.getArgByName("name")] }

override DataFlow::Node getValueArg() { result in [this.getArg(1), this.getArgByName("value")] }

override predicate nameAllowsNewline() { none() }

override predicate valueAllowsNewline() { none() }
}
}

0 comments on commit 581e7f5

Please sign in to comment.