Skip to content

Commit

Permalink
Second round feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwstubbs committed Oct 30, 2024
1 parent 0483b80 commit ac411f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
13 changes: 6 additions & 7 deletions python/ql/lib/semmle/python/frameworks/Bottle.qll
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ module Bottle {
*/
module App {
/** Gets a reference to a Bottle application (an instance of `bottle.Bottle`) */
API::Node instance() { result = bottle().getMember("Bottle").getReturn() }

/** Gets a reference to a Bottle application (an instance of `bottle.app`) */
API::Node app() { result = bottle().getMember("app").getReturn() }
API::Node app() { result = bottle().getMember(["Bottle", "app"]).getReturn() }
}

/** Provides models for functions that are possible "views" */
Expand All @@ -42,13 +39,13 @@ module Bottle {
ViewCallable() { this = any(BottleRouteSetup rs).getARequestHandler() }
}

/** Get methods that reprsent a route in Bottle */
string routeMethods() { result = ["route", "get", "post", "put", "delete", "patch"] }

private class BottleRouteSetup extends Http::Server::RouteSetup::Range, DataFlow::CallCfgNode {
BottleRouteSetup() {
this =
[
App::instance().getMember(routeMethods()).getACall(),
App::app().getMember(routeMethods()).getACall(),
bottle().getMember(routeMethods()).getACall()
]
Expand All @@ -68,8 +65,10 @@ module Bottle {

/** Provides models for the `bottle.response` module */
module Response {
/** Gets a reference to the `bottle.response` module. */
API::Node response() { result = bottle().getMember("response") }
/** Gets a reference to the `bottle.response` module or instantiation of Bottle Response class. */
API::Node response() {
result = [bottle().getMember("response"), bottle().getMember("Response").getReturn()]
}

/** A response returned by a view callable. */
class BottleReturnResponse extends Http::Server::HttpResponse::Range {
Expand Down
11 changes: 11 additions & 0 deletions python/ql/test/library-tests/frameworks/bottle/basic_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Source: https://bottlepy.org/docs/dev/tutorial.html#the-application-object
from bottle import Bottle, run

app = Bottle()

@app.route('/hello') # $ routeSetup="/hello"
def hello(): # $ requestHandler
return "Hello World!" # $ HttpResponse responseBody="Hello World!" mimetype=text/html

if __name__ == '__main__':
app.run(host='localhost', port=8080)

0 comments on commit ac411f1

Please sign in to comment.