fix(security): Use bounded parameters for reserved-tag init#1344
fix(security): Use bounded parameters for reserved-tag init#1344reddraconi wants to merge 1 commit intoTagStudioDev:mainfrom
Conversation
The startup migration that bumps tags-table autoincrement past the reserved range built two SQL statements with f-strings. While RESERVED_TAG_END is hard-coded at the moment, it's a scary pattern that can turn into a SQL injection site if that value ever originates from another location. I swapped the `tag_id` to a SQLAlchemy bind paramter (`:tag_id`) to fix that and so it matches the other queries in the codebase.
|
|
I mentioned that in the body it's a very minor thing. If there's never a a plan to move After I resumed working on issue #1247 this week, I felt like I got to go a good stopping point and wanted to double-check I didn't miss anything that might be helpful. If you'd like to toss this PR, that's cool, too. |
Also not to mention, TagStudio is a local program only, SQL injection isn't a security issue as the user has access to the database file already, they would get zero benefit from using SQL injection on data they already have access to. And even then, TagStudio stores no sensitive data. |
|
I think my cyber hat is cutting off circulation today and marking this as security was a bit dramatic. I was just looking at the SQL handling stuff and forgot this is local-only. What would you like to do with this and the PR? If you want me to submit it a simple code consistency cleanup, I'll be happy to do that, or we can just schwack all of it. |
Summary
The startup migration that bumps tags-table autoincrement past the reserved range is built from a pair of SQL statements using f-strings.
While
RESERVED_TAG_ENDis hard-coded at the moment, it's a scary pattern that can turn into a SQL injection site if that value ever originates from another location.I swapped the
tag_idto a SQLAlchemy bind paramter (:tag_id) to fix that and so it matches the other queries in the codebase.This really just amounts to a code smell that could be a footgun in the future.
Why no new tests
This a simple refactor with no behavioral changes.
make_tables(engine)is already exercised through every library-creating fixture in the existing test suite.Tasks Completed
pytest231 tests still passruff check src/tagstudio testsmypyon changed files