-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Complete v2.3.0 roadmap - S3 storage, dashboard enhancements, documentation #2
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: SilianZ <113701655+SilianZ@users.noreply.github.com>
| except ClientError as e: | ||
| if e.response["Error"]["Code"] == "404": | ||
| return web.HTTPNotFound() | ||
| logger.terror("storage.error.s3.express", hash=hash, e=e) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 days ago
In general, to fix information exposure via exceptions you should log detailed exception data on the server side and return only generic, non-sensitive error messages to clients. Avoid including str(e), stack traces, or other internal state directly in responses.
For this concrete case in core/storages/s3.py, the best fix is to replace web.HTTPError(text=str(e)) with generic error responses. We can keep the existing logging calls (logger.terror(...)) so that developers still have full diagnostic information, but change what is returned to the client:
- For
ClientErrorwhere the code is not"404", we can respond with a 502 or 500-level error with a generic message such as"Failed to access storage backend"or a localized equivalent. - For the generic
Exceptionhandler, respond with a generic 500 error (e.g.,web.HTTPInternalServerError) and a minimal message.
We already import locale from core.i18n; following existing patterns in the project, we can use it to obtain a localized generic error message key like "storage.error.s3.express". The only lines that need modification are 145 and 148 (the two return web.HTTPError(text=str(e)) statements). No new imports or helper methods are required.
-
Copy modified line R145 -
Copy modified line R148
| @@ -142,10 +142,10 @@ | ||
| if e.response["Error"]["Code"] == "404": | ||
| return web.HTTPNotFound() | ||
| logger.terror("storage.error.s3.express", hash=hash, e=e) | ||
| return web.HTTPError(text=str(e)) | ||
| return web.HTTPBadGateway(text=locale("storage.error.s3.express")) | ||
| except Exception as e: | ||
| logger.terror("storage.error.s3.express", hash=hash, e=e) | ||
| return web.HTTPError(text=str(e)) | ||
| return web.HTTPInternalServerError(text=locale("storage.error.s3.express")) | ||
|
|
||
| async def recycleFiles(self, files: FileList) -> None: | ||
| """Clean up files in S3 that are not in the valid file list""" |
| logger.terror("storage.error.s3.express", hash=hash, e=e) | ||
| return web.HTTPError(text=str(e)) | ||
| except Exception as e: | ||
| logger.terror("storage.error.s3.express", hash=hash, e=e) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 days ago
In general, to fix information exposure via exceptions, you should never send raw exception messages or stack traces back to the client. Instead, log detailed errors server-side and return a generic, user-safe error response (optionally with a stable error code that can be correlated in logs).
For this specific code, the best minimal fix is to keep the detailed logging (logger.terror("storage.error.s3.express", ...)) for diagnostics but replace web.HTTPError(text=str(e)) with a response that contains a generic message. We should do this for both the ClientError and generic Exception branches in express while keeping existing behavior (status codes, logging, counters) as intact as possible. Because we must not assume additional project structure, we can directly use a short, non-sensitive message like "Internal server error" in the HTTP error body and leave the status code to web.HTTPError’s default (500). No new imports are needed, since we are just changing the argument passed to web.HTTPError.
Concretely:
- In
core/storages/s3.py, locate theexpressmethod. - On line 145, change
web.HTTPError(text=str(e))toweb.HTTPError(text="Internal server error"). - On line 148, do the same: replace
str(e)with the same generic message. - Keep the
logger.terror(...)calls unchanged so that developers still see the real exception details in logs.
This preserves existing functionality (S3 presigned-URL creation, counter updates, logging, 404 behavior) while preventing sensitive information from being exposed to clients.
-
Copy modified line R145 -
Copy modified line R148
| @@ -142,10 +142,10 @@ | ||
| if e.response["Error"]["Code"] == "404": | ||
| return web.HTTPNotFound() | ||
| logger.terror("storage.error.s3.express", hash=hash, e=e) | ||
| return web.HTTPError(text=str(e)) | ||
| return web.HTTPError(text="Internal server error") | ||
| except Exception as e: | ||
| logger.terror("storage.error.s3.express", hash=hash, e=e) | ||
| return web.HTTPError(text=str(e)) | ||
| return web.HTTPError(text="Internal server error") | ||
|
|
||
| async def recycleFiles(self, files: FileList) -> None: | ||
| """Clean up files in S3 that are not in the valid file list""" |
… and updated README Co-authored-by: SilianZ <113701655+SilianZ@users.noreply.github.com>
…ration guides Co-authored-by: SilianZ <113701655+SilianZ@users.noreply.github.com>
…erval Co-authored-by: SilianZ <113701655+SilianZ@users.noreply.github.com>
Implements v2.3.0 roadmap: completes incomplete S3 storage backend, enhances dashboard UX, and restructures documentation with configuration examples.
S3 Storage Backend
Completed the partial
S3Storageimplementation:express()generates presigned URLs (1h TTL) via S3 clientgetMissingFiles()paginates bucket listings to identify sync gapsrecycleFiles()batch-deletes (1000 objects/request) files not in manifestasyncio.to_thread()to prevent event loop blockingFactory integration in
core/storages/__init__.pysupports configuration:Compatible with AWS S3, MinIO, Alibaba Cloud OSS, and S3-compatible services.
Dashboard Improvements
Documentation Restructuring
Added to both Chinese and English READMEs:
Example S3 configuration includes endpoint patterns for major providers (AWS, MinIO, Alibaba).
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.