-
Notifications
You must be signed in to change notification settings - Fork 32
🎨🔒️ Add string_types
Module for Strongly Validated API String Fields
#8526
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
🎨🔒️ Add string_types
Module for Strongly Validated API String Fields
#8526
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #8526 +/- ##
==========================================
+ Coverage 89.32% 89.49% +0.16%
==========================================
Files 1801 1584 -217
Lines 70811 65593 -5218
Branches 837 504 -333
==========================================
- Hits 63252 58702 -4550
+ Misses 7339 6759 -580
+ Partials 220 132 -88
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
ac96308
to
153107f
Compare
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.
Pull Request Overview
This PR introduces a new string_types.py
module that centralizes validation for string fields used in API schemas, replacing generic str
types with strongly validated custom types (NameSafeStr
, DescriptionSafeStr
, etc.) that enforce content safety rules and length constraints to protect against SQL/JS injection attacks.
Key Changes:
- Created
string_types.py
with validated string types that detect SQL/JS injection patterns - Applied new safe string types to API input schemas for folders, groups, projects, tags, and users
- Migrated truncated string types from
basic_types.py
tostring_types.py
with added safety validation
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.
Show a summary per file
File | Description |
---|---|
packages/models-library/src/models_library/string_types.py | New module defining validated string types with injection protection |
packages/models-library/src/models_library/basic_types.py | Removed legacy truncated string type definitions |
packages/models-library/src/models_library/api_schemas_webserver/folders_v2.py | Updated folder name fields to use NameSafeStr |
packages/models-library/src/models_library/api_schemas_webserver/groups.py | Updated group label/description fields to use safe string types |
packages/models-library/src/models_library/api_schemas_webserver/users.py | Updated user profile and search fields to use safe string types |
packages/models-library/src/models_library/api_schemas_webserver/projects.py | Updated import path for truncated string types |
packages/models-library/src/models_library/users.py | Added UserNameSafeID type with input safety validation |
services/web/server/src/simcore_service_webserver/tags/schemas.py | Updated tag schemas to use safe string types and moved ColorStr definition |
services/api-server/src/simcore_service_api_server/api/routes/studies.py | Updated import path for truncated string types |
services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml | Added pattern constraints to OpenAPI schema definitions |
packages/models-library/tests/test_string_types.py | New test file for safe string type validation |
packages/models-library/tests/test_basic_types.py | Removed tests for legacy truncated string types |
services/web/server/tests/unit/with_dbs/03/users/conftest.py | Moved imports to module level |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
packages/models-library/src/models_library/api_schemas_webserver/users.py
Outdated
Show resolved
Hide resolved
packages/models-library/src/models_library/api_schemas_webserver/users.py
Outdated
Show resolved
Hide resolved
services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml
Outdated
Show resolved
Hide resolved
@mergify queue |
🛑 Configuration not compatible with a branch protection settingThe branch protection setting |
🧪 CI InsightsHere's what we observed from your CI run for f75cc46. 🟢 All jobs passed!But CI Insights is watching 👀 |
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.
I like this PR, but I have one concern with it, which is existing data.
I'd like to avoid issue on production deployments with this PR.
Can you please import and check that running these validators on all the production data does not cause any errors?
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.
Please double check if these mega regexes are not subject to backtracking issues
👀 |
8de641f
to
9f0d5fd
Compare
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.
I'll follow up, thanks!
…eStr in folder and group schemas; enhance OpenAPI schema with validation patterns for name and description fields.
… and LongTruncatedStr to emphasize silent handling of large inputs; refactor import statement in test_projects.py for consistency.
…improved security; add SearchPatternSafeStr type for flexible pattern matching.
…or additional injection scenarios.
… test cases for input validation.
…oS test cases for input validation.
…ests to remove SQL injection cases.
…d improve input validation functions.
…lidation and add corresponding test cases.
…afety checks and update related validators.
… URL protocols in attributes.
ef1d88a
to
dd3ca38
Compare
|
@mergify queue |
🛑 Configuration not compatible with a branch protection settingThe branch protection setting |
What do these changes do?
This pull request introduces a new module,
string_types.py
, which centralizes and enforces stricter validation for string types used in API schemas. The main goal is to improve input safety and consistency across models by replacing generic string fields with custom, strongly validated types (such asNameSafeStr
,DescriptionSafeStr
, and others).This change is applied to several (but not all) API schemas related to folders, groups, projects, and users, and removes legacy string type definitions from
basic_types.py
.Input Safety & String Type Improvements
string_types.py
with new validated types:NameSafeStr
,DescriptionSafeStr
,GlobPatternSafeStr
,ShortTruncatedStr
, andLongTruncatedStr
, all enforcing stricter content and length rules, and protecting against SQL/JS injection.folders_v2.py
,groups.py
,projects.py
, andusers.py
to use the new safe string types instead of plainstr
or legacy types, improving input validation and safety for user-provided data.Follow up
NOTE that this is just an initial PR that set the bases and modifies some inputs as examples
web-
andpublic-
APIstest_safe_string_types
) in the response error body and complements 422 (unprocessable entyty) or 400 (Bad request) status codes @odeimaizRelated issue/s
How to test
test_basic_types.py
, as validation is now handled by the new types instring_types.py
.Dev-ops
None