-
Notifications
You must be signed in to change notification settings - Fork 1
Increase overall security #51
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
Open
RafaelCenzano
wants to merge
26
commits into
main
Choose a base branch
from
update-input-security
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
89d8906
add bleach and pytest and update fastapi and ruff
RafaelCenzano 73e8a1f
new sanitization and validation helper functions for improved security
RafaelCenzano 64751e3
validate against mongo content in inputs
RafaelCenzano cef2155
move common models and validation functions to common file
RafaelCenzano 84226ea
validate code is UUID v4
RafaelCenzano 31edd36
Add validation for backtest routes
RafaelCenzano 15402e5
Add validation for loanertech routes
RafaelCenzano bd37edb
add validation for laf routes
RafaelCenzano 0f8dcf0
add pytest for new functions in sanitize.py
RafaelCenzano 480d978
new pytest github action
RafaelCenzano 0690ac7
update pinned actions for workflows
RafaelCenzano 2af5353
update name to Pytest
RafaelCenzano 120098b
add permissions to workflow
RafaelCenzano 5c10769
remove regex and just depend on bleach to remove tags
RafaelCenzano e41e3a9
compile regex expression for more efficient execution
RafaelCenzano ccf7938
exclude valkey/redis dumps
RafaelCenzano 10a182d
Merge branch 'main' into update-input-security
RafaelCenzano 0a78910
chore: add version in comment
RafaelCenzano 266aded
refactor: use annotated type validation for style and pydantic v2 mat…
RafaelCenzano 6239d81
fix: ensure validation for objectid is used
RafaelCenzano 8d23f31
chore: create constant for location max length
RafaelCenzano ce7d0f9
test: cover all edge cases
RafaelCenzano 3db9ec7
chore: add strip to all output for course code validation
RafaelCenzano 58baa6c
chore: remove duplicate annotated namefilter type
RafaelCenzano a166cf6
refactor: phone regex
RafaelCenzano c813edb
fix: tests and mongo santize function
RafaelCenzano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| name: Pytest | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "**.py" | ||
| - "uv.lock" | ||
| - ".python-version" | ||
| - "pyproject.toml" | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5 | ||
|
|
||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 #v7.1.2 | ||
| with: | ||
| version: "latest" | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c #v6 | ||
| with: | ||
| python-version: "3.13.3" | ||
|
|
||
| - name: Install dependencies | ||
| run: uv sync --frozen --no-cache | ||
|
|
||
| - name: Run pytest | ||
| run: uv run pytest | ||
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||||||
| from __future__ import annotations | ||||||||||||||
|
|
||||||||||||||
| import re | ||||||||||||||
| from typing import Any | ||||||||||||||
|
|
||||||||||||||
| import bleach | ||||||||||||||
|
|
||||||||||||||
| _OBJECT_ID_RE = re.compile(r"^[a-fA-F0-9]{24}$") | ||||||||||||||
| _WHITESPACE_RE = re.compile(r"\s+") | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| def strip_tags(text: str) -> str: | ||||||||||||||
| if text is None: | ||||||||||||||
| return "" | ||||||||||||||
|
Comment on lines
+12
to
+14
|
||||||||||||||
| def strip_tags(text: str) -> str: | |
| if text is None: | |
| return "" | |
| def strip_tags(text: str | None) -> str: | |
| if text is None: | |
| raise TypeError("strip_tags() expected a string, got None") |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +0,0 @@ | ||
| from typing import Any | ||
|
|
||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| class ResponseModel(BaseModel): | ||
| data: Any | ||
| message: str | ||
|
|
||
|
|
||
| class BoolResponse(ResponseModel): | ||
| data: bool | ||
|
|
||
|
|
||
| class StringListResponse(ResponseModel): | ||
| data: list[str] | ||
|
|
||
|
|
||
| class IntResponse(ResponseModel): | ||
| data: int | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,30 @@ | ||
| from pydantic import BaseModel, Field | ||
| from typing import Annotated | ||
| from uuid import UUID | ||
|
|
||
| from pydantic import BaseModel, BeforeValidator, Field | ||
|
|
||
|
|
||
| def validate_uuid_code(v: str) -> str: | ||
| """Validate that a string is a valid UUID v4.""" | ||
| # Strip whitespace | ||
| v = v.strip() if isinstance(v, str) else str(v).strip() | ||
| try: | ||
| # Validate it's a valid UUID v4 | ||
| uuid_obj = UUID(v, version=4) | ||
| return str(uuid_obj) | ||
| except (ValueError, AttributeError): | ||
| raise ValueError("code must be a valid UUID v4") | ||
|
|
||
|
|
||
| UUIDCode = Annotated[str, BeforeValidator(validate_uuid_code)] | ||
|
|
||
|
|
||
| class TokenRequest(BaseModel): | ||
| code: str = Field(...) | ||
| code: UUIDCode = Field(...) | ||
|
|
||
| class Config: | ||
| json_schema_extra = { | ||
| "example": { | ||
| "code": "adsa-sda-dsa-ds-d-asd", | ||
| "code": "550e8400-e29b-41d4-a716-446655440000", | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.