Comprehensive Input Validation and Sanitization#13
Open
manny-uncharted wants to merge 7 commits intoakave-ai:mainfrom
Open
Comprehensive Input Validation and Sanitization#13manny-uncharted wants to merge 7 commits intoakave-ai:mainfrom
manny-uncharted wants to merge 7 commits intoakave-ai:mainfrom
Conversation
…rted/go-akavelink
Contributor
Author
|
@Abhay-2811 should we add ratelimiting to the endpoints |
Collaborator
|
@manny-uncharted Yes we can add a configurable rate limiting, I'll think it over and create new issue if needed. For now I'll review this PR and get back to you. |
Abhay-2811
requested changes
Nov 19, 2025
Collaborator
Abhay-2811
left a comment
There was a problem hiding this comment.
Hey @manny-uncharted I do not understand why there is a replica dir here?
Contributor
Author
|
I'd be resolving this now it's an error on my part |
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.
Summary
closes: #11
This PR implements comprehensive input validation and sanitization for the AkaveLink API to protect against common security vulnerabilities, including path traversal attacks, malicious file uploads, and injection attacks.
Changes Made
1. New Validation Package (
internal/validation/)Created a comprehensive validation package with the following features:
Bucket Name Validation:
File Name Validation:
File Upload Validation:
Sanitization Functions:
SanitizeBucketName()- Removes invalid characters, converts to lowercase, truncatesSanitizeFileName()- Removes path components, null bytes, and traversal patterns2. Validation Middleware (
internal/middleware/)Created HTTP middleware for request validation:
ValidateBucketName()- Validates bucket name URL parametersValidateFileName()- Validates file name URL parametersValidateBucketAndFileName()- Validates both bucket and file namesValidateContentLength()- Validates Content-Length headerSecurityHeaders()- Adds security HTTP headers to all responsesLogRequest()- Logs all incoming requests for audit trailsSecurity Headers Added:
X-Content-Type-Options: nosniff- Prevents MIME sniffingX-Frame-Options: DENY- Prevents clickjackingX-XSS-Protection: 1; mode=block- Enables XSS protectionContent-Security-Policy: default-src 'self'- Restricts resource loading3. Updated Handlers
Bucket Handlers (
internal/handlers/buckets.go):createBucketHandlerdeleteBucketHandlerFile Handlers (
internal/handlers/files.go):fileInfoHandler- Validates bucket and file nameslistFilesHandler- Validates bucket nameuploadHandler- Validates bucket name, file upload, and content lengthdownloadHandler- Validates bucket and file namesfileDeleteHandler- Validates bucket and file namesRouter (
internal/handlers/router.go):4. Comprehensive Test Suite
Unit Tests (
test/validation_test.go):Middleware Tests (
test/middleware_test.go):Integration Tests (
test/validation_integration_test.go):Attack Prevention
✅ Path Traversal - Blocked patterns:
..,/,\, URL-encoded variants✅ Malicious File Uploads - Size limits, MIME type validation, filename sanitization
✅ Injection Attacks - Input sanitization removes dangerous characters
✅ XSS Attacks - Security headers prevent script injection
✅ Clickjacking - X-Frame-Options header blocks iframe embedding
✅ MIME Sniffing - X-Content-Type-Options prevents browser MIME sniffing
Validation Error Responses
Standardized error responses with proper HTTP status codes:
{ "error": "Validation Error", "field": "bucketName", "message": "bucket name must contain only alphanumeric characters, hyphens, and underscores" }