"""점검 결과를 브라우저로 보여 주는 작은 Flask 보고서. 사용법: python report_app.py [포트] 같은 폴더의 audit-old.json, audit-new.json(pip-audit -f json 결과)과 hash-ok.json, hash-tampered.json(hash_check.py 결과)을 읽어 두 화면을 만든다. / pip-audit 점검 보고서 (고치기 전과 후) /hashes 해시 비교 (정상일 때와 내용이 바뀐 뒤) """ import html import json import sys from pathlib import Path from flask import Flask BASE = Path(__file__).resolve().parent app = Flask(__name__) STYLE = """""" def load(name): return json.loads((BASE / name).read_text(encoding="utf-8")) def audit_table(data): rows, total = [], 0 for dep in data["dependencies"]: vulns = {v["id"]: v for v in dep.get("vulns", [])} total += len(vulns) fixes = sorted({f for v in vulns.values() for f in v["fix_versions"]}) cls = "bad" if vulns else "ok" rows.append( f"{html.escape(dep['name'])}{html.escape(str(dep.get('version', '')))}" f"{len(vulns)}{html.escape(', '.join(fixes)) or '-'}" f"{html.escape(', '.join(sorted(vulns))) or '-'}" ) head = "패키지버전취약점수정 버전ID" return total, f"{head}{''.join(rows)}
" @app.get("/") def audit_page(): old_total, old_table = audit_table(load("audit-old.json")) new_total, new_table = audit_table(load("audit-new.json")) return ( f"의존성 점검 보고서{STYLE}" "

의존성 점검 보고서

" "

같은 requirements를 pip-audit로 점검한 결과입니다. 취약점은 중복을 뺀 건수입니다.

" f"

고치기 전: requirements-old.txt 취약점 {old_total}건

{old_table}" f"

고친 뒤: requirements.in 취약점 {new_total}건

{new_table}" ) def hash_box(title, data): rows = [] for r in data["rows"]: verdict = "일치" if r["match"] else "불일치" rows.append( f"{html.escape(r['name'])} {html.escape(r['version'])}" f"{html.escape(r['file'])}" f"잠금 파일{html.escape(', '.join(r['locked']))}" f"서버가 내준 파일{r['actual']}" f"판정{verdict}" ) return f"

{html.escape(title)}

{''.join(rows)}
" @app.get("/hashes") def hashes_page(): ok, bad = load("hash-ok.json"), load("hash-tampered.json") return ( f"해시 불일치 전후 비교{STYLE}" "

해시 불일치 전후 비교

" "

같은 이름과 같은 버전인데 서버가 내주는 파일의 내용이 바뀌면 sha256 값이 달라집니다.

" f"
{hash_box('정상일 때', ok)}{hash_box('내용이 바뀐 뒤', bad)}
" ) if __name__ == "__main__": app.run(host="127.0.0.1", port=int(sys.argv[1]) if len(sys.argv) > 1 else 19810)