Security review fixes: admin permissions, guest sessions, payment edge cases, assistant leaks
- Admin: refund/cancel/mark-resolved/Bazaar-link actions need change permission; question and curriculum import need add/delete; content browser needs view_question; guest device ids are shown to superusers only. - Accounts: registering a guest's phone revokes the guest's earlier sessions; self-deletion keeps Redemption, UserOffer and the phone's OTP rows; the public demo guest cannot be deleted (DEMO_GUEST_DEVICE_IDS); display-name contact filter covers any separator and social handles. - Payment: callback without Authority is 400; a second Bazaar purchase on a paid order is 409; orders snapshot credits/hearts/days at creation (payment.0011). - Assistant: a broken diagram no longer makes a streamed answer free; a late off-topic marker refuses the answer (not stored, not cached); a disconnect saves the partial answer; only KNOWN_COLLECTIONS are searched. - Infra: secret-key file is created atomically (workers no longer split keys); no default INTERNAL_SERVICE_KEY; Kavenegar key and Bazaar token kept out of error logs; Swagger/ReDoc pinned; schema throttled; docker compose bound to 127.0.0.1; non-ASCII digit ids are 400; ticket text capped at 5000. - docs/security-before-production.md: remaining open items 24-31 and the guard tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,9 @@ import logging
|
||||
|
||||
from .config import build_collection_name, resolve_grade_title, retrieval_top_k
|
||||
from .embedding import embed_text
|
||||
from .known_collections import filter_key_for_subject, is_math_subject, resolve_math_chapter
|
||||
from .known_collections import (
|
||||
KNOWN_COLLECTIONS, filter_key_for_subject, is_math_subject, resolve_math_chapter,
|
||||
)
|
||||
from .qdrant_store import search
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -29,6 +31,12 @@ def resolve_target(subject: str, grade_title: str, grade_id, lesson_number):
|
||||
return None, None, None
|
||||
|
||||
collection = build_collection_name(subject, grade_title)
|
||||
if collection not in KNOWN_COLLECTIONS:
|
||||
# subject و grade میتوانند از بدنهی درخواست بیایند؛ بیاین چک هر کاربری از هر collectionِ
|
||||
# Qdrantِ مشترک (از جمله مالِ تیمِ دیگر) متن میخواند و در usedChunks پس میگرفت.
|
||||
# نتیجه همان رفتارِ collectionِ ناموجود است: جوابِ بیcontext.
|
||||
logger.warning('rag.retrieve: collection %r در KNOWN_COLLECTIONS نیست، جستجو نشد', collection)
|
||||
return None, None, None
|
||||
filter_key = filter_key_for_subject(subject)
|
||||
if is_math_subject(subject):
|
||||
filter_value = resolve_math_chapter(subject, grade_title, lesson_number)
|
||||
|
||||
Reference in New Issue
Block a user