From 716f8b271763d8b429ef0248b961381c88e2cb16 Mon Sep 17 00:00:00 2001 From: bornunique911 Date: Wed, 1 Jul 2026 18:29:34 +0530 Subject: [PATCH 1/2] chore: add standalone OWASP cheat sheet refresh script --- scripts/update-cheatsheets.sh | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 scripts/update-cheatsheets.sh diff --git a/scripts/update-cheatsheets.sh b/scripts/update-cheatsheets.sh new file mode 100755 index 000000000..f914f240d --- /dev/null +++ b/scripts/update-cheatsheets.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +DB_PATH="${1:-$ROOT_DIR/standards_cache.sqlite}" +VENV_DIR="$ROOT_DIR/venv" + +if [[ ! -d "$VENV_DIR" ]]; then + python3 -m venv "$VENV_DIR" +fi + +source "$VENV_DIR/bin/activate" + +if ! python -c "import flask" >/dev/null 2>&1; then + pip install -r "$ROOT_DIR/requirements.txt" +fi + +if [[ ! -f "$DB_PATH" ]]; then + echo "Database file does not exist: $DB_PATH" >&2 + exit 1 +fi + +BACKUP_FILE="${DB_PATH}.$(date +%Y%m%d%H%M%S).bak" +cp "$DB_PATH" "$BACKUP_FILE" +if [[ ! -f "$BACKUP_FILE" ]]; then + echo "Failed to create backup at $BACKUP_FILE" >&2 + exit 1 +fi +echo "Created backup at $BACKUP_FILE" + +CRE_NO_CALCULATE_GAP_ANALYSIS=1 \ +CRE_NO_GEN_EMBEDDINGS=1 \ +python "$ROOT_DIR/cre.py" --cheatsheets_in --cache_file "$DB_PATH" + +python - "$DB_PATH" <<'PY' +import os +import sqlite3 +import sys + +db_path = sys.argv[1] +conn = sqlite3.connect(db_path) +cur = conn.cursor() + +github_prefix = "https://github.com/OWASP/CheatSheetSeries/tree/master/cheatsheets/" +official_prefix = "https://cheatsheetseries.owasp.org/cheatsheets/" + +rows = cur.execute( + """ + select id, link + from node + where name = 'OWASP Cheat Sheets' + and link like ? + """, + (f"{github_prefix}%",), +).fetchall() + +for node_id, link in rows: + filename = os.path.basename(link) + html_name = os.path.splitext(filename)[0] + ".html" + cur.execute( + "update node set link = ? where id = ?", + (f"{official_prefix}{html_name}", node_id), + ) + +conn.commit() +conn.close() +print(f"Normalized {len(rows)} OWASP Cheat Sheet links") +PY From 76283a229d5c7d51a8f3a0ddfaa22971b414e784 Mon Sep 17 00:00:00 2001 From: bornunique911 Date: Tue, 7 Jul 2026 17:38:51 +0530 Subject: [PATCH 2/2] fix: ensure requirements are always installed and improve backup filename uniqueness --- scripts/update-cheatsheets.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/update-cheatsheets.sh b/scripts/update-cheatsheets.sh index f914f240d..5e993d33a 100755 --- a/scripts/update-cheatsheets.sh +++ b/scripts/update-cheatsheets.sh @@ -11,16 +11,16 @@ fi source "$VENV_DIR/bin/activate" -if ! python -c "import flask" >/dev/null 2>&1; then - pip install -r "$ROOT_DIR/requirements.txt" -fi +# FIX: always install requirements to pick up new/updated packages +pip install -r "$ROOT_DIR/requirements.txt" if [[ ! -f "$DB_PATH" ]]; then echo "Database file does not exist: $DB_PATH" >&2 exit 1 fi -BACKUP_FILE="${DB_PATH}.$(date +%Y%m%d%H%M%S).bak" +# FIX: add PID to backup filename to avoid collisions +BACKUP_FILE="${DB_PATH}.$(date +%Y%m%d%H%M%S)_$$.bak" cp "$DB_PATH" "$BACKUP_FILE" if [[ ! -f "$BACKUP_FILE" ]]; then echo "Failed to create backup at $BACKUP_FILE" >&2 @@ -65,4 +65,4 @@ for node_id, link in rows: conn.commit() conn.close() print(f"Normalized {len(rows)} OWASP Cheat Sheet links") -PY +PY \ No newline at end of file