T09 · Insecure Skill Coding Practices
- Location
scripts/real_estate.sh:6- Finding
Arbitrary Python Code Execution Through Unsafe Shell Argument Interpolation
- Content
View full analysis
- Remediation
View remediation
&2 exit 2 } [[ "$DEAL_YMD" =~ ^[0-9]{6}$ ]] || { echo "Invalid contract month: expected YYYYMM" >&2 exit 2 } year=${DEAL_YMD:0:4} month=${DEAL_YMD:4:2} (( 10#$month >= 1 && 10#$month <= 12 )) || { echo "Invalid contract month" >&2 exit 2 } [[ "$NUM" =~ ^[0-9]+$ ]] || { echo "Invalid row count: expected a positive integer" >&2 exit 2 } (( NUM >= 1 && NUM <= 1000 )) || { echo "Invalid row count: expected a value from 1 to 1000" >&2 exit 2 } python3 - "$LAWD_CD" "$DEAL_YMD" "$NUM" <<'PY' import json import sys import urllib.parse import urllib.request import xml.etree.ElementTree as ET from pathlib import Path lawd_cd, deal_ymd, num = sys.argv[1:4] key = (Path.home() / ".config/data-go-kr/api_key").read_text().strip() base = ( "https://apis.data.go.kr/1613000/" "RTMSDataSvcAptTrade/getRTMSDataSvcAptTrade" ) params = urllib.parse.urlencode({ "serviceKey": key, "LAWD_CD": lawd_cd, "DEAL_YMD": deal_ymd, "pageNo": "1", "numOfRows": num, }) url = f"{base}?{params}" with urllib.request.urlopen(url, timeout=15) as response: data = response.read().decode() root = ET.fromstring(data) items = root.findall(".//item") result = [] for item in items: result.append({ "aptNm": item.findtext("aptNm", "").strip(), "dealAmount": item.findtext("dealAmount", "").strip(), "excluUseAr": item.findtext("excluUseAr", "").strip(), "floor": item.findtext("floor", "").strip(), "buildYear": item.findtext("buildYear", "").strip(), "dealYear": item.findtext("dealYear", ""), "dealMonth": item.findtext("dealMonth", "") ...[truncated 1054 chars]
