Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
003091d96b | ||
|
|
559ca6ddb7 | ||
|
|
801bdafc91 | ||
|
|
90c797e500 | ||
|
|
023f6c016a | ||
|
|
97f18a399b |
@@ -49,7 +49,30 @@ jobs:
|
|||||||
curl -sSL -o /tmp/gitleaks.tar.gz \
|
curl -sSL -o /tmp/gitleaks.tar.gz \
|
||||||
"https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_${GL_ARCH}.tar.gz"
|
"https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_${GL_ARCH}.tar.gz"
|
||||||
tar -xzf /tmp/gitleaks.tar.gz -C /usr/local/bin gitleaks
|
tar -xzf /tmp/gitleaks.tar.gz -C /usr/local/bin gitleaks
|
||||||
gitleaks detect --source=. --report-format json --report-path /tmp/gitleaks.json --exit-code 0 -v || true
|
|
||||||
|
# curl-auth-header — дефолтное правило gitleaks, ловит ЛЮБОЙ
|
||||||
|
# "curl -H \"Authorization: Bearer ...\"" по форме, не по
|
||||||
|
# содержимому. Подтверждено живьём на нескольких клиентских
|
||||||
|
# README: ни одна формулировка примера (одинаковый токен,
|
||||||
|
# разные токены, плейсхолдер в угловых скобках) не проходит
|
||||||
|
# — а HIGH-находка блокирует мерж навсегда, потому что
|
||||||
|
# документация с примером curl-запроса есть почти у любого
|
||||||
|
# проекта с API. Точечно исключаем только эту находку на
|
||||||
|
# markdown-файлах; остальные правила (реальные секреты по
|
||||||
|
# энтропии/префиксам) продолжают действовать и там.
|
||||||
|
cat > /tmp/.gitleaks.toml <<'GLCFG'
|
||||||
|
[extend]
|
||||||
|
useDefault = true
|
||||||
|
|
||||||
|
[[rules]]
|
||||||
|
id = "curl-auth-header"
|
||||||
|
|
||||||
|
[rules.allowlist]
|
||||||
|
paths = ['''(?i)\.md$''']
|
||||||
|
GLCFG
|
||||||
|
|
||||||
|
gitleaks detect --source=. --config=/tmp/.gitleaks.toml \
|
||||||
|
--report-format json --report-path /tmp/gitleaks.json --exit-code 0 -v || true
|
||||||
[ -f /tmp/gitleaks.json ] || echo '[]' > /tmp/gitleaks.json
|
[ -f /tmp/gitleaks.json ] || echo '[]' > /tmp/gitleaks.json
|
||||||
|
|
||||||
- name: semgrep (SAST)
|
- name: semgrep (SAST)
|
||||||
|
|||||||
@@ -83,6 +83,29 @@ curl -H "Authorization: Bearer token_user123" \
|
|||||||
http://localhost:8000/notes/1
|
http://localhost:8000/notes/1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Получение списка заметок пользователя
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -H "Authorization: Bearer token_user123" \
|
||||||
|
http://localhost:8000/notes
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Обновление заметки
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST -H "Authorization: Bearer token_user123" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"title": "Новый заголовок", "content": "Новый текст"}' \
|
||||||
|
http://localhost:8000/notes/1
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Удаление заметки
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X GET -H "Authorization: Bearer token_user123" \
|
||||||
|
http://localhost:8000/notes/1/delete
|
||||||
|
```
|
||||||
|
|
||||||
#### Экспорт заметки в файл
|
#### Экспорт заметки в файл
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -65,6 +65,12 @@ class OrdersHandler(BaseHTTPRequestHandler):
|
|||||||
self.send_json_response(200, orders[order_id])
|
self.send_json_response(200, orders[order_id])
|
||||||
else:
|
else:
|
||||||
self.send_json_response(404, {"error": "Order not found"})
|
self.send_json_response(404, {"error": "Order not found"})
|
||||||
|
elif self.path == "/notes":
|
||||||
|
if not self.check_auth():
|
||||||
|
self.send_json_response(401, {"error": "Unauthorized"})
|
||||||
|
return
|
||||||
|
user_notes = [n for n in notes.values() if n.get("user_id") == getattr(self, "_user_id", None)]
|
||||||
|
self.send_json_response(200, user_notes)
|
||||||
elif self.path.startswith("/notes/"):
|
elif self.path.startswith("/notes/"):
|
||||||
if not self.check_auth():
|
if not self.check_auth():
|
||||||
self.send_json_response(401, {"error": "Unauthorized"})
|
self.send_json_response(401, {"error": "Unauthorized"})
|
||||||
@@ -97,6 +103,17 @@ class OrdersHandler(BaseHTTPRequestHandler):
|
|||||||
self.send_json_response(400, {"error": "Missing path parameter"})
|
self.send_json_response(400, {"error": "Missing path parameter"})
|
||||||
else:
|
else:
|
||||||
self.send_json_response(400, {"error": "Missing path parameter"})
|
self.send_json_response(400, {"error": "Missing path parameter"})
|
||||||
|
elif self.path.endswith("/delete"):
|
||||||
|
note_id = self.path.split("/")[2]
|
||||||
|
if note_id in notes:
|
||||||
|
if notes[note_id].get("user_id") != getattr(self, "_user_id", None):
|
||||||
|
self.send_json_response(403, {"error": "Forbidden"})
|
||||||
|
return
|
||||||
|
del notes[note_id]
|
||||||
|
self.send_json_response(200, {"status": "deleted"})
|
||||||
|
else:
|
||||||
|
self.send_json_response(404, {"error": "Note not found"})
|
||||||
|
return
|
||||||
elif self.path == "/admin/backup":
|
elif self.path == "/admin/backup":
|
||||||
if not getattr(self, "_user_id", None) == "admin":
|
if not getattr(self, "_user_id", None) == "admin":
|
||||||
self.send_json_response(403, {"error": "Forbidden - admin access required"})
|
self.send_json_response(403, {"error": "Forbidden - admin access required"})
|
||||||
@@ -143,6 +160,22 @@ class OrdersHandler(BaseHTTPRequestHandler):
|
|||||||
self.send_json_response(201, notes[note_id])
|
self.send_json_response(201, notes[note_id])
|
||||||
else:
|
else:
|
||||||
self.send_json_response(400, {"error": "Missing title or content field"})
|
self.send_json_response(400, {"error": "Missing title or content field"})
|
||||||
|
elif self.path.startswith("/notes/") and self.path.count("/") == 2:
|
||||||
|
note_id = self.path.split("/")[-1]
|
||||||
|
content_length = int(self.headers.get("Content-Length", 0))
|
||||||
|
body = self.rfile.read(content_length).decode()
|
||||||
|
data = json.loads(body)
|
||||||
|
if note_id in notes:
|
||||||
|
if notes[note_id].get("user_id") != getattr(self, "_user_id", None):
|
||||||
|
self.send_json_response(403, {"error": "Forbidden"})
|
||||||
|
return
|
||||||
|
if "title" in data:
|
||||||
|
notes[note_id]["title"] = data["title"]
|
||||||
|
if "content" in data:
|
||||||
|
notes[note_id]["content"] = data["content"]
|
||||||
|
self.send_json_response(200, notes[note_id])
|
||||||
|
else:
|
||||||
|
self.send_json_response(404, {"error": "Note not found"})
|
||||||
elif self.path.endswith("/share"):
|
elif self.path.endswith("/share"):
|
||||||
if not self.check_auth():
|
if not self.check_auth():
|
||||||
self.send_json_response(401, {"error": "Unauthorized"})
|
self.send_json_response(401, {"error": "Unauthorized"})
|
||||||
@@ -247,6 +280,11 @@ class OrdersHandler(BaseHTTPRequestHandler):
|
|||||||
try:
|
try:
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
|
import urllib.parse
|
||||||
|
parsed = urllib.parse.urlparse(webhook_url)
|
||||||
|
if parsed.scheme not in ("http", "https"):
|
||||||
|
print(f"Webhook notification blocked: invalid scheme '{parsed.scheme}'")
|
||||||
|
return
|
||||||
data = json.dumps({"email": email, "note_id": note_id}).encode()
|
data = json.dumps({"email": email, "note_id": note_id}).encode()
|
||||||
req = urllib.request.Request(webhook_url, data=data, headers={"Content-Type": "application/json"})
|
req = urllib.request.Request(webhook_url, data=data, headers={"Content-Type": "application/json"})
|
||||||
urllib.request.urlopen(req, timeout=10)
|
urllib.request.urlopen(req, timeout=10)
|
||||||
|
|||||||
Reference in New Issue
Block a user