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

Prevent database connections to sqlite #9218

Merged
merged 3 commits into from
Mar 2, 2020

Conversation

suddjian
Copy link
Member

CATEGORY

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

SQLite allows users to create DBs locally on the machine running Superset. This is dangerous because it allows mapping the local filesystem and can also lead to DoS attacks. There is no good reason to be using SQLite as an analytics DB, so we've opted to prevent it from being used.

This change introduces a new flag PREVENT_UNSAFE_DB_CONNECTIONS which is true by default. Any other future unsafe db connections can be added to the same logic I've written here.

TEST PLAN

Unit tested, smoke tested locally

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

@willbarrett @craig-rueda @nytai

@willbarrett
Copy link
Member

It would be good to add tests for the endpoints to ensure that SQLite connection strings are rejected at the API layer. I think this deserves a partial integration test or two.

@dpgaspar
Copy link
Member

I think this is a case to write a note on UPDATING.md

Copy link
Member

@nytai nytai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's an api test failing. That should be enough to ensure the api rejects sqlite connection strings

Copy link
Member

@craig-rueda craig-rueda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with a few nits. Would be good to add an integration test or two

superset/views/core.py Outdated Show resolved Hide resolved
superset/views/database/mixins.py Outdated Show resolved Hide resolved
@codecov-io
Copy link

Codecov Report

Merging #9218 into master will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9218      +/-   ##
==========================================
+ Coverage   58.91%   58.92%   +0.01%     
==========================================
  Files         372      372              
  Lines       11996    11999       +3     
  Branches     2937     2940       +3     
==========================================
+ Hits         7068     7071       +3     
  Misses       4750     4750              
  Partials      178      178
Impacted Files Coverage Δ
...frontend/src/views/dashboardList/DashboardList.tsx 59.34% <0%> (ø) ⬆️
...uperset-frontend/src/views/chartList/ChartList.tsx 63.39% <0%> (ø) ⬆️
...ontend/src/components/ListView/TableCollection.tsx 90% <0%> (+1.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f73f8a...3ef1a0f. Read the comment docs.

@craig-rueda craig-rueda merged commit e01f24f into apache:master Mar 2, 2020
@suddjian suddjian deleted the sqlite-security branch March 2, 2020 21:13


def check_sqlalchemy_uri(uri):
if uri.startswith("sqlite"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suddjian should this be if uri.drivername == "sqlite":? Also could you add typing to this method so it's apparent the type of the uri method.

Copy link
Member Author

@suddjian suddjian Mar 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is merged but I can add typing in a new PR.

uri is a string so I assume you're referring to the output of make_url from sqlalchemy. make_url(uri).drivername == "sqlite" won't quite work in all cases because there are actually multiple drivers available for sqlite, each with their own protocol portion of the URI. We would need multiple checks, or make_url(uri).drivername.startswith("sqlite"). Any sqlite URI will start with "sqlite", however, so I think this way is simpler.

@hc128168 hc128168 mentioned this pull request May 6, 2020
3 tasks
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.36.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 0.36.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants