Security Audit Mitigations & Hardening#313
Open
Dhara124 wants to merge 2 commits into
Open
Conversation
f83b529 to
9f69f61
Compare
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.
Objective
This pull request implements critical security remediations identified during the recent adversarial audit. These changes harden the backend API against common attack vectors, including SSRF, IDOR, and unauthorized access, while aligning environments.
Files Changed & Rationale
1. Global Security & Authentication
Modified:
backend/anudesh_backend/settings.pyACCESS_TOKEN_LIFETIMEto 15 minutes to limit the window of opportunity for stolen tokens.CORS_ORIGIN_ALLOW_ALL = Trueconfiguration and established a strictCORS_ALLOWED_ORIGINSwhitelist to prevent cross-origin attacks.2. Chat & Media Functionality
Modified:
backend/functions/views.pychat_output: AddedUserRateThrottleto prevent abuse and exhaustion of LLM endpoint quotas.chat_log: Upgraded permissions toIsAuthenticated. Added payload size limits (1MB maximum) and schema validation to prevent Denial of Service (DoS) attacks via massive payloads.upload_chat_image: Implemented deep image inspection usingPillow. Images are now verified, stripped of EXIF data, and re-encoded to neutralize hidden malware/XSS vectors. Enforced strictContent-TypeandContent-Disposition: attachmentheaders via the Azure SDK to prevent malicious inline browser execution.3. Workspace Access Controls
Modified:
backend/workspaces/views.pybulk_add_members_to_projects: Fixed a critical Insecure Direct Object Reference (IDOR) vulnerability. The database query now explicitly filters projects by the workspace context (project = Project.objects.get(pk=pid, workspace_id=pk)), ensuring users cannot maliciously modify projects outside their authorized workspaces.4. Task Integrations
Modified:
backend/tasks/views.pyTransliterationAPIView: Applied strict URL-encoding (urllib.parse.quote) to user-supplied parameters used in internal HTTP requests. This mitigates Server-Side Request Forgery (SSRF) and Path Traversal vulnerabilities.How to Test
bulk_add_members_to_projectsendpoint using a valid project ID that belongs to a different workspace. Verify the request fails and does not expose or modify the unrelated project..phpor.jsdisguised as.jpg); verify the upload is rejected by Pillow.TransliterationAPIViewendpoint with path traversal payloads (e.g., passing../in the target language or data fields). Verify the payload is safely URL-encoded and does not traverse internal routing paths.chat_outputendpoint to verify that DRF throttling engages and returns a429 Too Many Requestsstatus code.