Skip to content

Commit 81f3609

Browse files
Formatting
1 parent dfc5192 commit 81f3609

File tree

1 file changed

+36
-42
lines changed

1 file changed

+36
-42
lines changed

python/ql/lib/semmle/python/frameworks/Streamlit.qll

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,74 +28,68 @@ module Streamlit {
2828

2929
override string getSourceType() { result = "Streamlit user input" }
3030
}
31-
/**
32-
* The Streamlit SQLConnection class, which is used to create a connection to a SQL Database.
33-
* Streamlit wraps around SQL Alchemy for most database functionality, and adds some on top of it, such as the `query` method.
34-
* Streamlit can also connect to Snowflake and Snowpark databases, but the modeling is not the same, so we need to limit the scope to SQL databases.
35-
* https://docs.streamlit.io/develop/api-reference/connections/st.connections.sqlconnection#:~:text=to%20data.-,st.connections.SQLConnection,-Streamlit%20Version
36-
* We can connect to SQL databases for example with `import streamlit as st; conn = st.connection('pets_db', type='sql')`
37-
*/
31+
32+
/**
33+
* The Streamlit SQLConnection class, which is used to create a connection to a SQL Database.
34+
* Streamlit wraps around SQL Alchemy for most database functionality, and adds some on top of it, such as the `query` method.
35+
* Streamlit can also connect to Snowflake and Snowpark databases, but the modeling is not the same, so we need to limit the scope to SQL databases.
36+
* https://docs.streamlit.io/develop/api-reference/connections/st.connections.sqlconnection#:~:text=to%20data.-,st.connections.SQLConnection,-Streamlit%20Version
37+
* We can connect to SQL databases for example with `import streamlit as st; conn = st.connection('pets_db', type='sql')`
38+
*/
3839
private class StreamlitSqlConnection extends API::CallNode {
3940
StreamlitSqlConnection() {
4041
exists(StringLiteral str, API::CallNode n |
41-
str.getText() = "sql"
42-
and
43-
n = API::moduleImport("streamlit").getMember("connection").getACall()
44-
and
45-
DataFlow::exprNode(str).(DataFlow::LocalSourceNode)
46-
.flowsTo([n.getArg(1), n.getArgByName("type")])
47-
and this = n
42+
str.getText() = "sql" and
43+
n = API::moduleImport("streamlit").getMember("connection").getACall() and
44+
DataFlow::exprNode(str)
45+
.(DataFlow::LocalSourceNode)
46+
.flowsTo([n.getArg(1), n.getArgByName("type")]) and
47+
this = n
4848
)
49-
5049
}
5150
}
51+
5252
/**
5353
* The `query` call that can execute raw queries on a connection to a SQL database.
5454
* https://docs.streamlit.io/develop/api-reference/connections/st.connection
5555
*/
5656
private class QueryMethodCall extends DataFlow::CallCfgNode, SqlExecution::Range {
57-
5857
QueryMethodCall() {
59-
exists(StreamlitSqlConnection s |
60-
this = s.getReturn().getMember("query").getACall())
58+
exists(StreamlitSqlConnection s | this = s.getReturn().getMember("query").getACall())
6159
}
6260

6361
override DataFlow::Node getSql() { result in [this.getArg(0), this.getArgByName("sql")] }
6462
}
6563

66-
67-
/**
68-
* The Streamlit SQLConnection.connect() call, which returns a a new sqlalchemy.engine.Connection object.
69-
* Streamlit creates a connection to a SQL database basing off SQL Alchemy, so we can reuse the models that we already have.
70-
*/
71-
private class StreamlitSQLAlchemyConnection extends SqlAlchemy::Connection::InstanceSource {
72-
StreamlitSQLAlchemyConnection() {
73-
exists(StreamlitSqlConnection s |
74-
this = s.getReturn().getMember("connect").getACall())
64+
/**
65+
* The Streamlit SQLConnection.connect() call, which returns a a new sqlalchemy.engine.Connection object.
66+
* Streamlit creates a connection to a SQL database basing off SQL Alchemy, so we can reuse the models that we already have.
67+
*/
68+
private class StreamlitSqlAlchemyConnection extends SqlAlchemy::Connection::InstanceSource {
69+
StreamlitSqlAlchemyConnection() {
70+
exists(StreamlitSqlConnection s | this = s.getReturn().getMember("connect").getACall())
7571
}
7672
}
7773

78-
/**
79-
* The underlying SQLAlchemy Engine, accessed via `st.connection().engine`.
80-
* Streamlit creates an engine to a SQL database basing off SQL Alchemy, so we can reuse the models that we already have.
81-
*/
82-
private class StreamlitSqlAlchemyEngine extends SqlAlchemy::Engine::InstanceSource {
74+
/**
75+
* The underlying SQLAlchemy Engine, accessed via `st.connection().engine`.
76+
* Streamlit creates an engine to a SQL database basing off SQL Alchemy, so we can reuse the models that we already have.
77+
*/
78+
private class StreamlitSqlAlchemyEngine extends SqlAlchemy::Engine::InstanceSource {
8379
StreamlitSqlAlchemyEngine() {
84-
exists(StreamlitSqlConnection s |
85-
this = s.getReturn().getMember("engine").asSource())
80+
exists(StreamlitSqlConnection s | this = s.getReturn().getMember("engine").asSource())
8681
}
8782
}
8883

89-
/**
90-
* The SQLAlchemy Session, accessed via `st.connection().session`.
91-
* Streamlit can create a session to a SQL database basing off SQL Alchemy, so we can reuse the models that we already have.
92-
* For example, the modeling for `session` includes an `execute` method, which is used to execute raw SQL queries.
93-
* https://docs.streamlit.io/develop/api-reference/connections/st.connections.sqlconnection#:~:text=SQLConnection.engine-,SQLConnection.session,-Streamlit%20Version
94-
*/
84+
/**
85+
* The SQLAlchemy Session, accessed via `st.connection().session`.
86+
* Streamlit can create a session to a SQL database basing off SQL Alchemy, so we can reuse the models that we already have.
87+
* For example, the modeling for `session` includes an `execute` method, which is used to execute raw SQL queries.
88+
* https://docs.streamlit.io/develop/api-reference/connections/st.connections.sqlconnection#:~:text=SQLConnection.engine-,SQLConnection.session,-Streamlit%20Version
89+
*/
9590
private class StreamlitSqlSession extends SqlAlchemy::Session::InstanceSource {
9691
StreamlitSqlSession() {
97-
exists(StreamlitSqlConnection s |
98-
this = s.getReturn().getMember("session").asSource())
92+
exists(StreamlitSqlConnection s | this = s.getReturn().getMember("session").asSource())
9993
}
10094
}
10195
}

0 commit comments

Comments
 (0)