forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on mainFiltered to tests/unit/test_service_authz_adversarial.pyClear filter

2026-09-23

fix: accept folded scope labels in the authorization gateAhmet Kaan Gümüş · d70a24c
fix: accept folded scope labels in the authorization gate

The backend forwards the derived (sinif, ders) pair with the course
TITLE ("Biyoloji"); _scope_denied compared byte-exact against the
corpus slug ("biyoloji"), so summary/question requests were refused
with scope_mismatch. Compare with bridge.subject_map.fold as fallback
after exact match: same-course case/diacritic variants pass, a folded
different course still refuses (fail-closed #42/#43 unchanged).
Local-Gate: dd29e790e65b4f2943e493a278bb29a37b422722 (1415 passed, 32s)

2026-09-11

fix(guvenlik): ozet/soru yollarinda kasa izolasyonu bypass'ini kapat (KRITIK)Kadir Yönak · a6dc248
fix(guvenlik): ozet/soru yollarinda kasa izolasyonu bypass'ini kapat (KRITIK)

EXP-010'da KOSULARAK kanitlanmis iki KRITIK acik.

#42 (SEC-01) -- Istemci `scope` ile kendini yetkilendirme:
`handler.summarize`/`generate_questions` erisim kararini istemcinin govdede
gonderdigi `scope.sinif`/`scope.ders` ile veriyordu
(`scope.get("sinif") or getattr(self.doc,"sinif")`) -> saldirgan `can_access`'e
hem ozneyi hem NESNEYI kendisi bildiriyordu. Kanitlanan somuru: 9. sinif
matematik ogrencisi, auth'un urettigi GERCEK rolüyle
`scope={"pages":[40],"sinif":"9","ders":"matematik"}` gonderip 12-biyoloji
icerigini ozetletti. Mevcut test yalniz DURUST saldirgani deniyordu -> yanlis
guvence veriyordu.

#43 (SEC-02) -- Taninmayan/eksik rol -> fail-OPEN:
`_role_ctx` cozulemeyen rolde None donuyor, ama iki yoldaki koruma
`if role_ctx is not None:` oldugu icin rol cozulemeyince kontrol TAMAMEN
atlaniyordu. Urun hiyerarsisi parent<student<teacher<manager<admin ama `Role`
enum'inda **manager YOKTU** -> backend mesru bir mudur icin
{"role":"manager",...} urettiginde her doküman, her kapsam aciliyordu. Rol hic
gonderilmediginde de ayni sonuc.

Cozum:
- Tek yetki kapisi `_scope_denied(service, scope, role)`; iki yol da onu cagirir
  (testle sabit: eski `if role_ctx is not None:` ve `scope.get("sinif") or`
  desenleri geri gelirse test kirilir).
- Kapsamin sinif/dersi YALNIZ sunucu gercekinden (`self.doc`) alinir. Istemci
  bir kapsam etiketi gonderirse bu bir yetki GIRDISI degil, sunucu gercegiyle
  ESLESME SARTI olur; uyusmazsa `scope_mismatch`.
- Rol yok/cozulemiyor -> `role_required` (fail-closed), varsayilan olarak ACIK.
- `Role.MANAGER` eklendi ve kurum-kapsamli ALLOW olarak tanimlandi (artik
  "taninmayan rol" yoluyla degil, BILINCLI olarak yetkili).
- API-CONTRACT'a iki yeni reason kodu + backend'in ne yapmasi gerektigi yazildi.

14 dusmanca test: sahte scope (iki yolda), dursut saldirgan, kismi sahtecilik,
mesru istek, mudur rolu, rolsuz istek, cozulemeyen roller, dict-olmayan rol,
bos ders_list, ve iki yolun AYNI kapiyi kullandigi.

DURUSTLUK DUZELTMESI: EXP-010 `"STUDENT "` degerini de "cozulemez" saymisti;
aslinda `_role_ctx` `.strip().lower()` uyguladigi icin gecerli role cozuluyor ve
kapsam kontrolune giriyor -- yani o deger bir fail-open yolu DEGILDI. Testte
ayri ayri kayitli.

Ayrica `test_service.QuestionsTests` guncellendi: eski hali rolsuz istekte soru
uretilmesini bekliyordu, yani SEC-02'nin fail-open davranisinin kaydiydi.

576 birim testi yesil.

Refs #42, #43