Open
Conversation
…rabilities 修复:增强下载端点路径/文件名校验并清理示例敏感配置
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.
Motivation
platform、video_id、文件名前缀等输入直接信任导致的路径穿越与任意文件覆盖风险。Content-Type生成图片扩展名导致的不安全扩展或错误后缀。Description
app/api/endpoints/download.py中新增并使用sanitize_name、resolve_download_dir、build_safe_file_path、get_safe_image_extension等辅助函数对平台、类型、文件名和扩展名进行净化与白名单校验,并基于Path.resolve()校验目标目录与文件路径以防路径逃逸。DEFAULT_HEADERS,并在fetch_data/fetch_data_stream中使用该默认值以避免不一致行为。FileResponse或传入merge_bilibili_video_audio时使用安全的路径字符串。crawlers/tiktok/web/config.yaml和crawlers/douyin/web/config.yaml中的Cookie/msToken示例值,替换为显式占位符PLEASE_REPLACE_WITH_YOUR_OWN_COOKIE/PLEASE_REPLACE_WITH_YOUR_OWN_MSTOKEN,以避免敏感凭据被误提交或复用。Testing
python -m compileall app crawlers,所有改动相关模块均能成功编译。app/api/endpoints/download.py与两个爬虫配置样例文件,变更符合安全加固目标。SyntaxWarning(app/web/views/ViewsUtils.py),该问题为既有警告且未由本次改动引入。