v1.0 - Version stable: multi-PC, détection UI-DETR-1, 3 modes exécution
- Frontend v4 accessible sur réseau local (192.168.1.40) - Ports ouverts: 3002 (frontend), 5001 (backend), 5004 (dashboard) - Ollama GPU fonctionnel - Self-healing interactif - Dashboard confiance Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
222
test_input_validation_simple.py
Normal file
222
test_input_validation_simple.py
Normal file
@@ -0,0 +1,222 @@
|
||||
it(1)s.ex
|
||||
syprint_exc() traceback. raceback
|
||||
mport t ie}")
|
||||
ng: { testi during❌ Errorint(f"\n pr e:
|
||||
on as Excepti except s.exit(1)
|
||||
sy")
|
||||
sues!em has isyst sonalidatiInput v"\n❌ t( prin :
|
||||
else0)
|
||||
.exit( sys ")
|
||||
ly!ng correctsystem workition validaputn✅ In("\ print ess:
|
||||
f succ i
|
||||
n()uccess = mai s try:
|
||||
_":
|
||||
n_maime__ == "__
|
||||
if __na True
|
||||
|
||||
return")
|
||||
== completed =l tests== Aln=print("\
|
||||
|
||||
}")CTED'se '❌ REJEs_valid elif result.iIZED' '✅ SANIT Status: {t(f" ")
|
||||
prinzed_value}t.sanitiresulnitized: {Sa nt(f" ")
|
||||
priml_input}htiginal: { Or(f"
|
||||
printFalse)ml=t, allow_htpul_instring(htmate_r.validlidatova result = pt>'
|
||||
)</scriert("xss"ipt>alput = '<scr html_in:")
|
||||
izationL sanitesting HTM\n4. T print("TML
|
||||
nitisation H# Test 4: Sa
|
||||
")
|
||||
n}': '{injectio {status}rint(f" p ALLOWED"
|
||||
e "❌ elst.is_validresul if not ED" BLOCK= "✅ status injection)
|
||||
ate_string(idor.validatsult = val re
|
||||
ons:injectiin nosql_tion injecor f
|
||||
]
|
||||
|
||||
; }' true() { return 'function ".*"}',
|
||||
"$regex": '{',
|
||||
.password"}= this =username: "this."$where" '{
|
||||
ns = [ql_injectionos")
|
||||
empts:jection attL in NoSQsting"\n3. Teprint(QL
|
||||
oSctions N: Injeest 3
|
||||
# T
|
||||
}'")onctius}: '{inje {statf" int( pr
|
||||
OWED"ALL"❌ lid else esult.is_va if not rD"OCKE "✅ BLstatus =
|
||||
n)jectiog(inate_strinvalidtor.idaalt = v resul ctions:
|
||||
injein sql_n njectio
|
||||
for i]
|
||||
|
||||
"words pass * FROMECT SEL "UNION='1",
|
||||
"1' OR '1' -",
|
||||
- users;ROP TABLE "'; D
|
||||
tions = [ecl_inj
|
||||
sqempts:")ttjection aL inesting SQt("\n2. TQL
|
||||
prinons Scti 2: Inje # Test
|
||||
a}'")
|
||||
}: '{datstatus {f" print(D"
|
||||
EJECTEelse "❌ Rid esult.is_valED" if r "✅ ACCEPTtatus = s a)
|
||||
at_string(didatealidator.val vult =es ruts:
|
||||
n valid_inp for data i)
|
||||
|
||||
mode=Trueator(strict_leInputValidr = Simpalidato3"]
|
||||
val data 12rm"no, m"ple.coxamer@ed", "ushello worl[" = lid_inputs")
|
||||
vauts: inpidTesting val"1. print(ides
|
||||
alrées vTest 1: Ent
|
||||
#
|
||||
m ===\n")steon Syput Validatit Ines"=== T
|
||||
print(""tion."de valida du système ncipal"Test pri
|
||||
""main():
|
||||
|
||||
|
||||
def tized_valueresult.sanireturn
|
||||
")
|
||||
rs)}ult.erron(res: {'; '.joime}eld_na for {fi faileddation"ValiError(fonalidatie InputV rais
|
||||
is_valid:ult. not res if
|
||||
d_name)
|
||||
, fiel, allow_htmlx_lengthng(value, madate_stritor.valiidaesult = vale)
|
||||
rode=Tru(strict_mdatorInputValile = Simpvalidator
|
||||
ng."""e strientréne t sanitise ude e"Vali"":
|
||||
") -> strutinpme: str = "ield_na= False, f_html: bool ow all 000,
|
||||
th: int = 1ng, max_lestre: (valung_inputstriate_
|
||||
def validme__}]"
|
||||
|
||||
ta).__natype(danprintable:{e}[uld_namn f"{fie retur ption:
|
||||
ept Exce exc
|
||||
r
|
||||
n data_stetur r
|
||||
)
|
||||
strcape(data_ml.esr = htdata_st ux
|
||||
es dangeres caractèrle Échapper #
|
||||
|
||||
"0] + "...tr[:20ta_s = da data_str 200:
|
||||
ta_str) >len(da if
|
||||
ogsr les ltaille pouLimiter la #
|
||||
a)
|
||||
r = str(dat data_st
|
||||
else: )
|
||||
(',', ':')ors=at separii=True,ure_asc ensta,son.dumps(da_str = j data st)):
|
||||
dict, lita, (nce(danstasi if i ry:
|
||||
t"""
|
||||
ng.ggipour le loées nn des do"Sanitise ""
|
||||
-> str:data")r = ": st, field_namef, data: Any_logging(sel_forf sanitize
|
||||
deings)
|
||||
, warnrorsitized, erlid, sanvaResult(is_tionrn Valida retu == 0
|
||||
errors)len( = is_valid
|
||||
|
||||
anitized), '', s1F\x7F]'E-\xC\x0\x008\x0Br'[\x00-\xre.sub(= zed anitie
|
||||
scontrôl de ractèress caer le # Nettoy
|
||||
|
||||
nitized)escape(sazed = html.ti sani tml:
|
||||
llow_hot a if ncessaire
|
||||
i néML sSanitizer HT #
|
||||
)
|
||||
ttern" pas NoSQLs suspicioume} contain"{field_naend(fapprnings. wa :
|
||||
else
|
||||
pattern")tionNoSQL injecial ins potent contaeld_name}nd(f"{fipeerrors.ap ode:
|
||||
lf.strict_m if se
|
||||
value):n.search( if patter :
|
||||
ql_patternsself._nosattern in for p
|
||||
SQLnjections Noer les i # Vérifi
|
||||
tern")
|
||||
pat SQL s suspiciousme} containfield_nappend(f"{ warnings.a
|
||||
else: )
|
||||
pattern"ionl SQL injectins potentianame} contad_fielappend(f"{ errors. mode:
|
||||
self.strict_ if
|
||||
alue):n.search(v if patter tterns:
|
||||
lf._sql_pan in seatter for pns SQL
|
||||
ectioes injr lifie# Vér
|
||||
h]
|
||||
gtlue[:max_lenzed = vaiti san
|
||||
")ters} characength_lmaxd to {} truncate{field_nameppend(f"ngs.a warni e:
|
||||
els
|
||||
x_length}")th of {maximum lengeeds maxcld_name} eend(f"{fieerrors.app
|
||||
trict_mode:self.s if :
|
||||
_lengthe) > max len(valu ifr
|
||||
ongueuifier la lVér#
|
||||
|
||||
rnings), wane, errors, Noesult(FalselidationRreturn Va ")
|
||||
ring a stt beame} musf"{field_nors.append( err str):
|
||||
value,nce(not isinsta
|
||||
if
|
||||
zed = value saniti
|
||||
nings = [] war []
|
||||
=rors er s."""
|
||||
aractère chaîne de cunede "Vali ""Result:
|
||||
> Validation") -put"in= name: str lse, field_ool = Fa_html: bllow a
|
||||
, 1000 int =max_length:ue: str, valring(self, validate_st
|
||||
defNS]
|
||||
ATTERCTION_Pf.NOSQL_INJEn in sel patterCASE) for.IGNOREttern, ree.compile(pa[rerns = pattlf._nosql_
|
||||
seATTERNS]TION_PNJECSQL_Iern in self.E) for pattASre.IGNORECttern, ile(pas = [re.compternf._sql_pat
|
||||
selanceerformpour ps patterns r lepile # Com
|
||||
e
|
||||
= Falstiveg_sensi.lo selfode
|
||||
strict_mrict_mode = stlf. ser."""
|
||||
idateuse le val""Initiali "True):
|
||||
ool = t_mode: bstric(self, __init__ def
|
||||
|
||||
|
||||
].|db\.)"s\hi r"(t
|
||||
.*\})","(\{\s*\$ r ,
|
||||
ut\b)"tTimeoval\b|\bse|\be*\(tion\s"(func r",
|
||||
n|\$nin)$lt|\$i|\|\$gtregex|\$ne$where|\$ r"(\[
|
||||
TERNS = N_PATINJECTIO
|
||||
NOSQL_on NoSQLr injectiux pourengens da # Patter]
|
||||
|
||||
)"
|
||||
\besqlbsp_execut r"(\b)",
|
||||
l\shel\bxp_cmd r"(;])",
|
||||
"([\'\" r,
|
||||
ERROR)\b)"|ONIPT|ONLOADSCRIPT|VBSCRPT|JAVASCRI"(\b( r",
|
||||
*|\*/)\ r"(--|#|/
|
||||
*\d+)",+\s*=\s)\s+\dNION|OR|AND"(\b(U r",
|
||||
UTE)\b)ER|EXEC|EXECALTCREATE|DROP|ATE|DELETE||INSERT|UPD\b(SELECT r"( = [
|
||||
ATTERNS ECTION_PSQL_INJQL
|
||||
ection S pour injangereuxterns d # Pat"
|
||||
|
||||
ié.""eur simplifes utilisatntréd'eValidateur
|
||||
"""tor:datVali SimpleInpu
|
||||
|
||||
classass
|
||||
p"
|
||||
ée.""cturité détede sécion """Violat
|
||||
ionError):putValidatError(InyViolations Securitss
|
||||
|
||||
|
||||
clas
|
||||
patrée."""on d'en de validatireur """Erption):
|
||||
nError(ExceutValidatioass Inp
|
||||
|
||||
|
||||
clrnings = []f.wa sel
|
||||
s None:ngs i self.warni if]
|
||||
[elf.errors = s
|
||||
is None:elf.errors if s (self):
|
||||
post_init__def __
|
||||
str]
|
||||
ngs: List[
|
||||
warnistr]ors: List[ err
|
||||
alue: Anysanitized_v bool
|
||||
id: is_val."""
|
||||
ntréeon d'une ealidatiat de v""Résult
|
||||
"ult:estionRss Validaclass
|
||||
cla
|
||||
@dataue
|
||||
|
||||
valitive__sensonfig, hashty_cecuri get_simportnfig y_cority.securit.secum corerectly
|
||||
frofig dionsecurity cort ))
|
||||
|
||||
# Imprente__).par(Path(__filinsert(0, stys.path.thon path
|
||||
sroot to Pyproject # Add the s
|
||||
|
||||
ort dataclaslasses impm datacional
|
||||
frost, Opty, Ling import Antypiom Path
|
||||
frportthlib imom paon
|
||||
frport jsrt html
|
||||
imort re
|
||||
impomp
|
||||
i osys
|
||||
import
|
||||
|
||||
import s"""
|
||||
tly.ecionality dirng the functes by testimport issus iis bypassety.
|
||||
Thtionalion funcidatiinput valfor le test
|
||||
Simp"ython3
|
||||
""n/env p#!/usr/bi
|
||||
Reference in New Issue
Block a user