Refactor mssqlshell.py to improve code structure#2189
Open
harshnair75567-cloud wants to merge 1 commit into
Open
Refactor mssqlshell.py to improve code structure#2189harshnair75567-cloud wants to merge 1 commit into
harshnair75567-cloud wants to merge 1 commit into
Conversation
Author
|
the code was written by myself I did seek ai assistance while writing the description |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
user input is interpolated directly into SQL query strings in several (do_) functions without escaping single quotes first. This means a user can break out of the intended SQL string by including a single quote in their input.
do_exec_as_login, do_exec_as_user, do_xp_dirtree, do_xp_cmdshell and do_sp_start_job are the affected functions
sql_query() already uses replace("'", "''") when wrapping queries for linked server execution. This PR applies the same escaping consistently to user input before it enters the query string in the affected functions.
each change is a single .replace("'", "''") call on the input string.
The sql_query() function does escape single quotes when a linked server is active via use_link, however this only applies to that specific code path. In the default usage with no linked server active the if self.at block is skipped entirely and the raw unescaped input goes directly to the SQL server. So the escaping needs to happen at the input level in each (do_) function, not rely on sql_query() to handle it