Koruma doğruluğu düzeltmeleri, güven ağı, dokümantasyon ve CI#2
Open
saracmert wants to merge 2 commits into
Open
Koruma doğruluğu düzeltmeleri, güven ağı, dokümantasyon ve CI#2saracmert wants to merge 2 commits into
saracmert wants to merge 2 commits into
Conversation
Roadmap 1 & 2: korumayı gerçekten çalışır kılan düzeltmeler + güven ağı. Recognizer/engine: - Tip anahtarlarını tek kaynakta topla (PiiTypes); IBAN "IBAN_TR" uyumsuzluğunu gider (artık skorlanır ve redakte edilir) - TCKN dil kapısını kaldır (checksum yeterli); ASCII gövdelerde de bulunur - PhoneRecognizer ulusal formatı bölgeyle ayrıştırır (05xx... tespit edilir) - IBAN boşluklu (4'lü gruplu) gösterimi tanır - Adres anahtar sözcüklerini kelime sınırıyla eşle (yanlış pozitif giderildi) - DOB takvim + gelecek doğrulaması; kredi kartı regex + Troy/Discover/JCB/ Maestro/Diners ve 13/19 haneli Visa - Regex ReDoS: MatchTimeout + güvenli e-posta deseni - Engine: çakışma çözümü, risk clamp, açık 0 ağırlığı, filtreler NER'e de Middleware: - Body swap'ı try/finally ile koru; block gövdesi istemciye ulaşır ve detection header'ları temizlenir - Redaksiyon sonrası Content-Length güncelle - ResponseCaptureStream: yalnızca analiz edilebilir tipleri ve boyut sınırına kadar tamponla; büyük/streaming yanıtları doğrudan akıt (OOM/SSE giderildi) - İstek gövdesi boyut sınırı; charset kontrolü; culture-invariant header; metod filtresi büyük/küçük harf duyarsız Options/DI/edge: - DataGuardianOptions.Validate() ve başlangıçta doğrulama - AddDataGuardian(IConfiguration/Action) + UseDataGuardian overload'ları - Edge snippet: fail-closed seçeneği, NaN/eksik header ve virgül ondalık Güven ağı ve CI: - xUnit + TestHost ile recognizer/engine/middleware/options testleri - CI feature dallarında da çalışır; trx + coverage artifact - Dependabot NuGet "/" + github-actions; kullanılmayan Google.Protobuf kaldırıldı Dokümantasyon: - docs/ (configuration, recognizers, scoring, actions, security, edge, contributing), CHANGELOG.md, README güncellendi, XML doc yorumları Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EQCGkU1zZXK3oCoAxPgCzf
There was a problem hiding this comment.
Pull request overview
Bu PR, DataGuardian’ın PII tespit/sınıflandırma doğruluğunu ve güvenliğini artırmayı, middleware’in HTTP davranışlarını daha güvenilir hale getirmeyi, kapsamlı test/dokümantasyon eklemeyi ve CI/Dependabot entegrasyonunu güçlendirmeyi hedefliyor.
Changes:
- Tanıyıcılarda doğruluk + güvenlik iyileştirmeleri (tip anahtarlarını
PiiTypesile birleştirme, regex timeout/ReDoS koruması, IBAN/telefon/TCKN/DOB/kredi kartı düzeltmeleri). - Middleware’de güvenilir request/response analiz-redaksiyon-blok akışı (stream swap try/finally, body size/charset/content-type kontrolleri, Content-Length düzeltmeleri, header davranışları).
- xUnit + TestHost test paketi,
docs/dokümantasyonu, CI’de test/coverage artifact’ları ve Dependabot kapsamı.
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Devoplus.DataGuardian.Tests/RecognizerTests.cs | Tanıyıcı regresyon testleri (email/tckn/phone/iban/cc/dob/address) |
| tests/Devoplus.DataGuardian.Tests/OptionsTests.cs | Options doğrulama + tip anahtarı tutarlılık testleri |
| tests/Devoplus.DataGuardian.Tests/MiddlewareTests.cs | Middleware E2E davranış testleri (Tag/Block/Redact/filtreler) |
| tests/Devoplus.DataGuardian.Tests/EngineTests.cs | Engine skor/filtre/overlap/weight regresyon testleri |
| tests/Devoplus.DataGuardian.Tests/Devoplus.DataGuardian.Tests.csproj | TestHost ve güncel test paketleri |
| src/Devoplus.DataGuardian/SimpleLanguage.cs | TR/EN dil tahminini ASCII Türkçe kelimelerle güçlendirme |
| src/Devoplus.DataGuardian/Recognizers/TcknRecognizer.cs | TCKN’yi dil bağımsız + timeout + PiiTypes ile düzeltme |
| src/Devoplus.DataGuardian/Recognizers/PhoneRecognizer.cs | Ulusal telefon parse’ı için region mantığı + timeout + PiiTypes |
| src/Devoplus.DataGuardian/Recognizers/IBANRecognizer.cs | Boşluklu IBAN + mod-97 iyileştirmeleri + PiiTypes |
| src/Devoplus.DataGuardian/Recognizers/EmailRecognizer.cs | ReDoS güvenli email regex + timeout + PiiTypes |
| src/Devoplus.DataGuardian/Recognizers/DobRecognizer.cs | DOB kalendar/future validasyonu + timeout + PiiTypes |
| src/Devoplus.DataGuardian/Recognizers/CreditCardRecognizer.cs | Kredi kartı regex + şema kapsamı + timeout + PiiTypes |
| src/Devoplus.DataGuardian/Recognizers/AddressRecognizer.cs | Kelime sınırıyla adres anahtar kelime eşleştirme + timeout + PiiTypes |
| src/Devoplus.DataGuardian/PiiTypes.cs | Tip anahtarları için tek kaynak (weights/redact/hits hizası) |
| src/Devoplus.DataGuardian/Internal/ResponseCaptureStream.cs | Yanıtı sadece uygun içeriklerde/limit dahilinde bufferlayan stream wrapper |
| src/Devoplus.DataGuardian/Devoplus.DataGuardian.csproj | XML doc üretimi + paket metadata + sürüm 1.1.0 |
| src/Devoplus.DataGuardian/DataGuardianOptions.cs | Yeni/iyileştirilmiş seçenekler + Validate() |
| src/Devoplus.DataGuardian/DataGuardianMiddleware.cs | Request/response analizi, blok/redaksiyon, charset/size kontrolü, Content-Length güncelleme |
| src/Devoplus.DataGuardian/DataGuardianExtensions.cs | DI + pipeline extension overload’ları (AddDataGuardian/UseDataGuardian) |
| src/Devoplus.DataGuardian/DataGuardianEngine.cs | Overlap çözümü, clamp, weight(0) disable semantiği, NER filtre uygulaması |
| samples/Devoplus.DataGuardian.SampleApi/Program.cs | Örnek API’yi DI + config binding kullanımına taşıma |
| samples/Devoplus.DataGuardian.SampleApi/appsettings.json | Sample için DataGuardian konfig bölümü |
| README.md | Kullanım/dokümantasyon/konfig örneklerini güncelleme |
| edge/dataguardian-snippet.js | Edge policy’de fail-open/closed + güvenli sayı parse’ı |
| docs/security.md | Tehdit modeli, header oracle, redaksiyon ve DoS notları |
| docs/scoring.md | Skor formülü ve parametrelerin açıklaması |
| docs/recognizers.md | Tanıyıcı davranışları + NER sınırlamaları |
| docs/edge.md | Edge dağıtımı ve konfig değişkenleri |
| docs/contributing.md | Repo yapısı + tanıyıcı ekleme/test/CI rehberi |
| docs/configuration.md | Tüm seçeneklerin referansı |
| docs/actions.md | Tag/Redact/Block davranışı + redaksiyon stilleri |
| CHANGELOG.md | 1.1.0 değişiklik özeti ve migrasyon notları |
| .github/workflows/dotnet.yml | CI: test results + coverage artifact upload |
| .github/dependabot.yml | NuGet + GitHub Actions güncellemelerini haftalığa genişletme |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+55
to
+59
| public static IApplicationBuilder UseDataGuardian(this IApplicationBuilder app, Action<DataGuardianOptions> configure) | ||
| { | ||
| if (configure is null) throw new ArgumentNullException(nameof(configure)); | ||
| var options = new DataGuardianOptions(); | ||
| configure(options); |
Comment on lines
+16
to
+19
| static readonly Regex Rx = new( | ||
| @"\b\d(?:[ \-]?\d){12,18}\b", | ||
| RegexOptions.Compiled, | ||
| TimeSpan.FromMilliseconds(200)); |
Comment on lines
+179
to
+188
| /// <summary>Reads the request body up to the size cap. Returns (body, oversize); body is null when skipped.</summary> | ||
| private async Task<(string? body, bool oversize)> ReadRequestBodyAsync(HttpContext ctx) | ||
| { | ||
| ctx.Request.EnableBuffering(); | ||
| using var reader = new StreamReader(ctx.Request.Body, Encoding.UTF8, leaveOpen: true); | ||
| var body = await reader.ReadToEndAsync(); | ||
| ctx.Request.Body.Position = 0; | ||
| return body; | ||
| var stream = ctx.Request.Body; | ||
|
|
||
| if (ctx.Request.ContentLength is long declared && declared > _opt.MaxBodySizeBytes) | ||
| { | ||
| stream.Position = 0; | ||
| return (null, true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Özet
Bu PR, kod analizinde tespit edilen ve varsayılan yapılandırmada PII korumasını sessizce devre dışı bırakan hataları giderir, bir test/güven ağı ekler, kapsamlı dokümantasyon getirir ve testleri CI'a entegre eder. (Analiz raporundaki yol haritasının 1. ve 2. maddeleri.)
CI (
.NET CI) bu dalda çalıştı: build 0 uyarı/0 hata, 42/42 test geçti, coverage + trx artifact olarak yüklendi.Korumayı gerçekten çalışır kılan düzeltmeler
IBANüretirkenWeights/RedactTypesIBAN_TRbekliyordu; IBAN ağırlık 1 alıyor ve hiç redakte edilmiyordu. Tüm tip anahtarları tek kaynakta (PiiTypes) birleştirildi.05xx…)DefaultPhoneRegion/dil bölgesiyle ayrıştırılır (eski"ZZ"her seferinde istisna fırlatıyordu).have→ave,katalog→katyanlış pozitifleri giderildi).MatchTimeout; güvenli e-posta deseni.Middleware / HTTP
try/finallyile korunur (downstream istisnada orijinal stream geri yüklenir).-Detectedheader'ları bloklanan yanıtta temizlenir (oracle önlenir).Content-Lengthgüncellenir (Kestrel uyuşmazlık hatası giderildi).ResponseCaptureStream: yalnızca analiz edilebilir içerik türleri veMaxBodySizeBytes'a kadar tamponlanır; büyük/streaming (SSE) yanıtlar doğrudan akıtılır (OOM ve streaming bozulması giderildi).Motor / Options / DI / Edge
clamp(0,10), açık0ağırlığı tipi devre dışı bırakır, entity filtreleri NER hit'lerine de uygulanır.DataGuardianOptions.Validate()ve başlangıçta doğrulama.AddDataGuardian(IConfiguration/Action)+UseDataGuardianoverload'ları (DI + konfigürasyon bağlama).Güven ağı ve CI
Microsoft.AspNetCore.TestHostile recognizer/engine/middleware/options testleri (42 test). Her düzeltilen hata için bir regresyon kilidi.trx+ coverage artifact yükler./+ github-actions. KullanılmayanGoogle.Protobufbağımlılığı kaldırıldı.Dokümantasyon
docs/(configuration, recognizers, scoring, actions, security, edge, contributing),CHANGELOG.md, güncellenmiş README, genel API'lerde XML doc yorumları.appsettingsiçindeWeights/RedactTypesiçinIBAN_TRkullananlarIBANolarak güncellemelidir. AyrıntıCHANGELOG.md'de.Kapsam dışı (Roadmap v2/v3)
NER'in derin sorunları (token→karakter ofset eşlemesi, tokenizer API bağlaması, dinamik ONNX girdileri, pencereleme) bu PR'da ele alınmadı; NER v1.x'te skor/etiketleme için işaretlendi, redaksiyon için önerilmiyor (
docs/recognizers.md).🤖 Generated with Claude Code
Generated by Claude Code