Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Bottle Framework Support #17370

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/ql/lib/change-notes/2024-08-30-bottle-tornado.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: majorAnalysis
---
* Added modeling of the `bottle` and `tornado` framework, leading to new remote flow sources and header writes
1 change: 1 addition & 0 deletions python/ql/lib/semmle/python/Frameworks.qll
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private import semmle.python.frameworks.Anyio
private import semmle.python.frameworks.Asyncpg
private import semmle.python.frameworks.Baize
private import semmle.python.frameworks.BSon
private import semmle.python.frameworks.Bottle
private import semmle.python.frameworks.CassandraDriver
private import semmle.python.frameworks.Cherrypy
private import semmle.python.frameworks.ClickhouseDriver
Expand Down
109 changes: 109 additions & 0 deletions python/ql/lib/semmle/python/frameworks/Bottle.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* Provides classes modeling security-relevant aspects of the `bottle` PyPI package.
* See https://bottlepy.org/docs/dev/.
*/

private import python
private import semmle.python.Concepts
private import semmle.python.dataflow.new.DataFlow
Fixed Show fixed Hide fixed
private import semmle.python.ApiGraphs
private import semmle.python.dataflow.new.RemoteFlowSources
private import semmle.python.frameworks.internal.InstanceTaintStepsHelper

/**
* INTERNAL: Do not use.
*
* Provides models for the `bottle` PyPI package.
* 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") }

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` or `bottle.web.RequestHandler.add_header` method.
*
* See https://bottlepy.org/docs/dev/api.html#bottle.BaseResponse.set_header
*/
class BottleResponseHandlerSetHeaderCall extends Http::Server::ResponseHeaderWrite::Range,
DataFlow::MethodCallNode
{
BottleResponseHandlerSetHeaderCall() {
this = response().getMember(["set_header", "add_header"]).getACall()
}

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() }
}

module Request {

Check warning on line 51 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::Request
API::Node request() { result = bottle().getMember("request") }

Check warning on line 52 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::Request::request/0

private class Request extends RemoteFlowSource::Range {
Request() { this = request().asSource() }

override string getSourceType() { result = "bottle.request" }
}

/**
* Taint propagation for `bottle.request`.
*
* See https://bottlepy.org/docs/dev/api.html#bottle.request
*/
private class InstanceTaintSteps extends InstanceTaintStepsHelper {
InstanceTaintSteps() { this = "bottle.request" }

override DataFlow::Node getInstance() {
result = request().getAValueReachableFromSource()
}

override string getAttributeName() {
result in ["headers", "query", "forms", "params", "json", "url"]
}

override string getMethodName() { none() }

override string getAsyncMethodName() { none() }
}
}

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") }

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 {
API::Node name;
API::Node value;

HeaderWriteSubscript() {
exists(API::Node holder |
holder = instance() and
this = holder.asSource() and
value = holder.getSubscriptAt(name)
)
}

override DataFlow::Node getNameArg() { result = name.asSink() }

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

override predicate nameAllowsNewline() { none() }

override predicate valueAllowsNewline() { none() }
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
testFailures
failures
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import python
import experimental.meta.ConceptsTest
Loading