-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: LSDV-5348: More robust and uniform SSRF defenses #4483
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
Conversation
✅ Deploy Preview for label-studio-docs-new-theme canceled.
|
✅ Deploy Preview for heartex-docs canceled.
|
I see there's some import-related unit test failures; will fix this tomorrow. question for reviewers: would changing this default value to True be an option? |
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## develop #4483 +/- ##
===========================================
+ Coverage 75.44% 75.46% +0.02%
===========================================
Files 156 156
Lines 12314 12297 -17
===========================================
- Hits 9290 9280 -10
+ Misses 3024 3017 -7 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM good work!
* fix: lsdv-5348: More robust and uniform SSRF defenses * fix import path * fix more issues with tests (incl. a flake from telemetry) * fix broken test by mocking url validator * regex excaping for codeql
* fix: lsdv-5348: More robust and uniform SSRF defenses * fix import path * fix more issues with tests (incl. a flake from telemetry) * fix broken test by mocking url validator * regex excaping for codeql Co-authored-by: Jo Booth <[email protected]>
* fix: lsdv-5348: More robust and uniform SSRF defenses * fix import path * fix more issues with tests (incl. a flake from telemetry) * fix broken test by mocking url validator * regex excaping for codeql
PR fulfills these requirements
[fix|feat|ci|chore|doc]: TICKET-ID: Short description of change made
ex.fix: DEV-XXXX: Removed inconsistent code usage causing intermittent errors
Change has impacts in these area(s)
(check all that apply)
Describe the reason for change
While reviewing a CodeQL finding (https://github.com/heartexlabs/label-studio/security/code-scanning/586) which turned out to be a false positive, a few shortcomings in the SSRF defense code were identified:
url_is_local
implementation would throw an exception in the UI when a URL value likeasdf
was passed. Note that it was only called when SSRF_PROTECTION_ENABLED is True.After this change, the result is
url_is_local
function, tested to see whether the URL began with "file://" in the uploader. This check would have been possible to bypass by using "FILE://" as the scheme, but luckily would have led to the above (unintentional) exception fromurl_is_local
if SSRF protection was enabled viasettings.SSRF_PROTECTION_ENABLED
. Additionally,requests.get
, which we have been using to fetch data sincefflag_fix_back_lsdv_4568_import_csv_links_03032023_short
was enabled, throws an exception for afile://
scheme by default.urllib.parse.urlparse
was previously used in the implementation ofurl_is_local
;requests
by contrast usesurrlib3
to parse URLs. Per https://claroty.com/wp-content/uploads/2022/01/Exploiting-URL-Parsing-Confusion.pdf, to minimize risk of exploits stemming from parser inconsistencies, it's best to minimize the number of URL parsers used in any application.What does this fix?
See screenshots above; this definitely fixes a low-level exception reaching the UI if SSRF_PROTECTION_ENABLED, and may also help protect LS against other exploits.
What is the new behavior?
(if this is a breaking or feature change)
What is the current behavior?
(if this is a breaking or feature change)
What libraries were added/updated?
urllib3
was exact pinned to 1.26.16, which was the versionpip show
revealed was already installed in the LS app container.This is because
urllib3.util.parse_url
is now imported in core/utils/io.pyDoes this change affect performance?
(if so describe the impacts positive or negative)
Does this change affect security?
This change should make our SSRF defenses more robust, and adds testing.
What alternative approaches were there?
(briefly list any if applicable)
What feature flags were used to cover this change?
fflag_fix_back_lsdv_4568_import_csv_links_03032023_short
was removed by this change. AFAIK this feature flag is enabled everywhere.Does this PR introduce a breaking change?
(check only one)
A feature flag has been removed.
What level of testing was included in the change?
(check all that apply)
Which logical domain(s) does this change affect?
URL data uploader, ML Backend API