一、审计修复(另一侧完成,我复核通过) - 认证/限流:_client_ip 归一、限流统一走 rate_limit._SlidingTable(超限只淘汰最旧 key, 不再整表 clear 自毁)、每用户会话上限 10 + 过期清理 - 邮件验证码:锁内原子占位 → 锁外发信 → 成功落码,失败回滚冷却(并发不再双发) - 租赁:rentals 部分唯一索引(同 order_id 只允许一行 expired=0,迁移前先查重)、 开锁幂等落库、Timer 代号机制(取消/重排同临界区)、minutes=null 兜底、 自动还车 30s×6 → 1m/2m/5m/10m 退避 - 安全:ring 四接口登录 + 任务归属校验(Bearer 或 ?token=,校验 sessions 表)、 共享还车坐标不再伪造、代开锁 IntegrityError 兜底、token 配置原子写(fsync + 0600) - 入口鉴权:8 个历史/分析接口未登录 401(HTTP 与 rtn_code 同时给)、 analysis.html 带 Bearer + 未登录门 + 截断提示、历史查询 LIMIT 60000 并回传 truncated - UX 四个 P0:计时条出现、真实单走 /api/order/return 而 reminder 走 /api/rental/return、 定位失败不伪造坐标(三选一弹窗)、地图/配置/脚本失败统一落到可自救失败卡片 - 测试:新增 6 个文件 62 例;既有 test_history_30d 只补登录前置 二、我复核时发现并修掉的 7 处 ① email_verify.record_cooldown 的 expires 写成 now,会被 send_code 开头的 _cleanup_locked 整条删掉 —— 任何人发一次验证码就废掉「未注册邮箱」的冷却, 找回密码又能枚举邮箱是否注册。改为活过冷却窗口,并补 3 例测试 ② timer.py 两处落库(自动续租 INSERT、sync 复活 UPDATE)没防新唯一索引: 撞索引抛 IntegrityError 会让巡检线程退出,该单从此没有计时器/自动还车(上游还在计费)。 新增 _active_rental_id_for_order(),捕获后复用存活行 ③ (0,0) 当合法坐标会先发给上游:/record/return 不校验范围,宽松后端会把车"还"在海里。 新增 _coords_usable(),不可用就跳过原始点;候选列表永远丢掉第 0 项 ④ boot_smoke.py 按旧契约要求 200,加鉴权后永远失败 → HTTPError 401 视为「未登录,预期」 ⑤ 自动还车「不放弃」缺绝对上限:加 AUTO_RETURN_GIVE_UP_SECONDS=6h,到点只告警一次并停手 ⑥ 索引谓词 aligned 到查重口径:COALESCE(expired,0)=0,旧定义自动重建 ⑦ 访问日志脱敏:?token= / ?ticket= / ?access_token= 的值替换为 ***(werkzeug + root logger) 否则容器日志里就是明文会话令牌 配套改写 tests/test_rental_dedup.py::test_return_accepts_zero_coordinates → test_return_treats_zero_coordinates_as_missing(原断言把 (0,0) 当合法值发上游) 三、验证 - python -m pytest -q → 234 passed(基线 231,净增 3) - node 5 套 → 44 pass / 0 fail - 14 个 .py ast.parse、node --check dist/app.js → 全部通过 - boot_smoke.py → exit=0;未登录 /api/history/stats、/api/analysis/overview、 /api/ring_progress/* 实测 401,/api/config 200 - 行为级:传 (0,0) 时上游只收到候选点;合法坐标仍先发上报值;唯一索引拦住重复插入
68 lines
3.7 KiB
PowerShell
68 lines
3.7 KiB
PowerShell
# 源码分发包:只包含代码、模板、必要静态资源和项目说明。
|
|
# 用法: pwsh -File scripts/pack_zip.ps1
|
|
$ErrorActionPreference = 'Stop'
|
|
$src = [IO.Path]::GetFullPath((Split-Path -Parent $PSScriptRoot))
|
|
$zip = Join-Path $src '1.zip'
|
|
$pendingZip = Join-Path $src '1.zip.tmp'
|
|
|
|
$include = @(
|
|
'.gitignore','LICENSE','README.md','app.py','db.py','campus.py','alerts.py','subscribe.py',
|
|
'email_utils.py','email_verify.py','generate_icons.py','map_cache.py','pytest.ini','rate_limit.py',
|
|
'rental_mail.py','requirements.txt','timer.py',
|
|
'update_creds_from_capture.py','wechat.py'
|
|
)
|
|
# 注意:server_config.json 不进分发包 —— 里面是百度服务端 AK/SK(BUG-09)。
|
|
# 部署走 git → docker 重建,服务端配置由部署环境自己放。
|
|
$dirs = @('routes','templates','static','scripts','tests')
|
|
$extensions = @('.py','.js','.cjs','.mjs','.css','.html','.ps1','.json',
|
|
'.svg','.png','.ico','.woff','.woff2','.ttf')
|
|
$files = [Collections.Generic.List[object]]::new()
|
|
foreach ($name in $include) {
|
|
$file = Join-Path $src $name
|
|
if (Test-Path -LiteralPath $file -PathType Leaf) { $files.Add((Get-Item -LiteralPath $file)) }
|
|
}
|
|
foreach ($dir in $dirs) {
|
|
$path = Join-Path $src $dir
|
|
if (-not (Test-Path -LiteralPath $path -PathType Container)) { continue }
|
|
Get-ChildItem -LiteralPath $path -Recurse -File | ForEach-Object {
|
|
$relative = [IO.Path]::GetRelativePath($src, $_.FullName).Replace('\','/')
|
|
if ($relative -match '(^|/)(__pycache__|\.pytest_cache|\.reasonix|backups|node_modules)(/|$)') { return }
|
|
if ($_.Name.StartsWith('.') -or $_.Name.StartsWith('_preview') -or $_.Name -eq '_layout_preview.html') { return }
|
|
if ($extensions -notcontains $_.Extension.ToLowerInvariant()) { return }
|
|
$files.Add($_)
|
|
}
|
|
}
|
|
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
try {
|
|
$stream = [IO.File]::Open($pendingZip, [IO.FileMode]::Create)
|
|
$archive = [IO.Compression.ZipArchive]::new($stream, [IO.Compression.ZipArchiveMode]::Create)
|
|
try {
|
|
foreach ($file in $files) {
|
|
$relative = [IO.Path]::GetRelativePath($src, $file.FullName).Replace('\','/')
|
|
[IO.Compression.ZipFileExtensions]::CreateEntryFromFile(
|
|
$archive, $file.FullName, $relative, [IO.Compression.CompressionLevel]::Optimal) | Out-Null
|
|
}
|
|
} finally { $archive.Dispose(); $stream.Dispose() }
|
|
|
|
$check = [IO.Compression.ZipFile]::OpenRead($pendingZip)
|
|
try {
|
|
$names = @($check.Entries | Select-Object -ExpandProperty FullName)
|
|
$required = @('app.py','db.py','map_cache.py','campus.py','alerts.py','subscribe.py',
|
|
'routes/export.py','routes/subscribe.py','routes/rental.py','routes/admin.py',
|
|
'templates/map.html','templates/admin.html','static/js/map.js',
|
|
'static/js/bike-clusters.js','static/js/settings-pages.js','static/css/bike-clusters.css','static/css/map-settings.css','requirements.txt')
|
|
$missing = @($required | Where-Object { $names -notcontains $_ })
|
|
if ($missing.Count) { throw "打包缺文件: $($missing -join ', ')" }
|
|
$unexpected = @($names | Where-Object {
|
|
$_ -match '(^|/)(downloads|artifacts|backups|logs|temp|sessions|__pycache__|\.git)/|\.(db|pem|key|crt|exe|zip|log|pyc)$|(^|/)(token_config|smtp_config|admin_config|secret_key|server_config)\.'
|
|
})
|
|
if ($unexpected.Count) { throw "压缩包包含非源码文件: $($unexpected -join ', ')" }
|
|
} finally { $check.Dispose() }
|
|
Move-Item -LiteralPath $pendingZip -Destination $zip -Force
|
|
$sizeKB = [math]::Round((Get-Item -LiteralPath $zip).Length / 1KB, 1)
|
|
Write-Host "1.zip 完成:$($names.Count) 个文件,$sizeKB KB(仅源码与必要资源)"
|
|
} finally {
|
|
if (Test-Path -LiteralPath $pendingZip) { Remove-Item -LiteralPath $pendingZip -Force }
|
|
}
|