Skip to content

Commit 2ab5721

Browse files
authored
Merge pull request #656 from cloudscribe/feature/482_2
#482 add missing checks to js sanitiser
2 parents ad41165 + aeb0a15 commit 2ab5721

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/cloudscribe.SimpleContent.Web/Services/Page/JsSecuritySanitizer.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public class JsSecuritySanitizer
6464
"location.href", // Commonly set to redirect
6565
"document.location", // Same
6666
"window.name", // Used to pass data between domains
67-
"localStorage", // Persistent local storage
68-
"sessionStorage", // Session-scoped storage
67+
"localStorage", // Persistent local storage (including .setItem, .getItem, etc.)
68+
"sessionStorage", // Session-scoped storage (including .setItem, .getItem, etc.)
6969
"indexedDB", // DB access
7070
"navigator.geolocation", // Gets user location
7171
"navigator.clipboard", // Read/write clipboard
@@ -108,6 +108,27 @@ private void TraverseNode(Node node, List<string> issues)
108108
{
109109
issues.Add($"Call to disallowed function: {ident.Name}");
110110
}
111+
112+
// Check for method calls on dangerous objects (e.g., localStorage.setItem)
113+
if (callExpr.Callee is MemberExpression memberCall &&
114+
memberCall.Object is Identifier objIdent)
115+
{
116+
// Check if it's a dangerous object being called
117+
if (DangerousProperties.Contains(objIdent.Name))
118+
{
119+
issues.Add($"Method call on disallowed object: {objIdent.Name}");
120+
}
121+
}
122+
}
123+
124+
// Check for dangerous constructor calls (new XMLHttpRequest(), new Function(), etc.)
125+
if (node is NewExpression newExpr)
126+
{
127+
if (newExpr.Callee is Identifier ident &&
128+
DangerousCalls.Contains(ident.Name))
129+
{
130+
issues.Add($"Use of disallowed constructor: new {ident.Name}()");
131+
}
111132
}
112133

113134
// Check for dangerous property access like window.location or document.cookie

0 commit comments

Comments
 (0)