Fossil SCM

Add taint confinement to unquoted inline variable expansion from Th_Render(). Improvements to the taint confinement error message.

drh 2025-04-24 17:05 trunk
Commit d259be4017e38a679dc76466782d224a6ae03a9908f5b52607b71d77539b44c7
1 file changed +7 -2
+7 -2
--- src/th_main.c
+++ src/th_main.c
@@ -2983,11 +2983,16 @@
29832983
}
29842984
rc = Th_GetVar(g.interp, (char*)zVar, nVar);
29852985
z += i+1+n;
29862986
i = 0;
29872987
zResult = (char*)Th_GetResult(g.interp, &n);
2988
- sendText(pOut,(char*)zResult, n, encode);
2988
+ if( !TH1_TAINTED(n)
2989
+ || encode
2990
+ || Th_ReportTaint(g.interp, "inline variable", zVar, nVar)==TH_OK
2991
+ ){
2992
+ sendText(pOut,(char*)zResult, n, encode);
2993
+ }
29892994
}else if( z[i]=='<' && isBeginScriptTag(&z[i]) ){
29902995
sendText(pOut,z, i, 0);
29912996
z += i+5;
29922997
for(i=0; z[i] && (z[i]!='<' || !isEndScriptTag(&z[i])); i++){}
29932998
if( g.thTrace ){
@@ -3086,11 +3091,11 @@
30863091
zVulnType = "SQL-injection";
30873092
}else{
30883093
zVulnType = "XSS";
30893094
}
30903095
nStr = TH1_LEN(nStr);
3091
- fossil_errorlog("possible %s vulnerability due to tainted TH1 %s: \"%.*s\"",
3096
+ fossil_errorlog("possible TH1 %s vulnerability due to tainted %s: \"%.*s\"",
30923097
zVulnType, zWhere, nStr, zStr);
30933098
if( strcmp(zDisp,"log")==0 ){
30943099
return 0;
30953100
}
30963101
if( strcmp(zDisp,"block")==0 ){
30973102
--- src/th_main.c
+++ src/th_main.c
@@ -2983,11 +2983,16 @@
2983 }
2984 rc = Th_GetVar(g.interp, (char*)zVar, nVar);
2985 z += i+1+n;
2986 i = 0;
2987 zResult = (char*)Th_GetResult(g.interp, &n);
2988 sendText(pOut,(char*)zResult, n, encode);
 
 
 
 
 
2989 }else if( z[i]=='<' && isBeginScriptTag(&z[i]) ){
2990 sendText(pOut,z, i, 0);
2991 z += i+5;
2992 for(i=0; z[i] && (z[i]!='<' || !isEndScriptTag(&z[i])); i++){}
2993 if( g.thTrace ){
@@ -3086,11 +3091,11 @@
3086 zVulnType = "SQL-injection";
3087 }else{
3088 zVulnType = "XSS";
3089 }
3090 nStr = TH1_LEN(nStr);
3091 fossil_errorlog("possible %s vulnerability due to tainted TH1 %s: \"%.*s\"",
3092 zVulnType, zWhere, nStr, zStr);
3093 if( strcmp(zDisp,"log")==0 ){
3094 return 0;
3095 }
3096 if( strcmp(zDisp,"block")==0 ){
3097
--- src/th_main.c
+++ src/th_main.c
@@ -2983,11 +2983,16 @@
2983 }
2984 rc = Th_GetVar(g.interp, (char*)zVar, nVar);
2985 z += i+1+n;
2986 i = 0;
2987 zResult = (char*)Th_GetResult(g.interp, &n);
2988 if( !TH1_TAINTED(n)
2989 || encode
2990 || Th_ReportTaint(g.interp, "inline variable", zVar, nVar)==TH_OK
2991 ){
2992 sendText(pOut,(char*)zResult, n, encode);
2993 }
2994 }else if( z[i]=='<' && isBeginScriptTag(&z[i]) ){
2995 sendText(pOut,z, i, 0);
2996 z += i+5;
2997 for(i=0; z[i] && (z[i]!='<' || !isEndScriptTag(&z[i])); i++){}
2998 if( g.thTrace ){
@@ -3086,11 +3091,11 @@
3091 zVulnType = "SQL-injection";
3092 }else{
3093 zVulnType = "XSS";
3094 }
3095 nStr = TH1_LEN(nStr);
3096 fossil_errorlog("possible TH1 %s vulnerability due to tainted %s: \"%.*s\"",
3097 zVulnType, zWhere, nStr, zStr);
3098 if( strcmp(zDisp,"log")==0 ){
3099 return 0;
3100 }
3101 if( strcmp(zDisp,"block")==0 ){
3102

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button