ReviewOS

also looking at this

stacks/stx

feat: router and runtime audit fixes

#1656
Closed fingersandmind wants to merge fix/router-and-runtime-audit-fixes into main
3 files +87 -42

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

packages/stx/src/signals.tsmodified+21-1
Changes to packages/stx/src/signals.ts
@@ -1426,6 +1426,10 @@ else {
14261426 };
14271427 window.addEventListener('popstate', syncFromUrl);
14281428 window.addEventListener('stx:navigate', syncFromUrl);
1429 onDestroy(function() {
1430 window.removeEventListener('popstate', syncFromUrl);
1431 window.removeEventListener('stx:navigate', syncFromUrl);
1432 });
14291433 return {
14301434 data: params,
14311435 get: function(key) { return params()[key]; },
@@ -1449,6 +1453,14 @@ else {
14491453 // ==========================================================================
14501454
14511455 var _queryCache = {};
1456 var _queryCacheKeys = [];
1457 var QUERY_CACHE_MAX = 50;
1458 function _evictQueryCache() {
1459 while (_queryCacheKeys.length > QUERY_CACHE_MAX) {
1460 var oldest = _queryCacheKeys.shift();
1461 delete _queryCache[oldest];
1462 }
1463 }
14521464
14531465 function useQuery(url, options) {
14541466 options = options || {};
@@ -1492,6 +1504,8 @@ else {
14921504 data.set(transformed);
14931505 isStale.set(false);
14941506 _queryCache[key] = { data: transformed, timestamp: Date.now() };
1507 if (_queryCacheKeys.indexOf(key) === -1) _queryCacheKeys.push(key);
1508 _evictQueryCache();
14951509 if (options.onSuccess) options.onSuccess(transformed);
14961510 // Schedule cache eviction
14971511 setTimeout(function() { delete _queryCache[key]; }, cacheTime);
@@ -1924,7 +1938,13 @@ else if (name === '@text' || name === ':text') {
19241938 }
19251939else if (name === '@html' || name === ':html') {
19261940 effect(() => {
1927 el.innerHTML = evalAttrExpr(value);
1941 var rawHtml = evalAttrExpr(value);
1942 // Basic sanitization: strip <script> tags and on* event handlers
1943 if (typeof rawHtml === 'string') {
1944 rawHtml = rawHtml.replace(/<script\\b[^>]*>[\\s\\S]*?<\\/script>/gi, '');
1945 rawHtml = rawHtml.replace(/\\son\\w+\\s*=\\s*["'][^"']*["']/gi, '');
1946 }
1947 el.innerHTML = rawHtml;
19281948 });
19291949 el.removeAttribute(name);
19301950 }