also looking at this
feat: router and runtime audit fixes
#1656
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.
| @@ -1426,6 +1426,10 @@ else { | ||
| 1426 | 1426 | }; |
| 1427 | 1427 | window.addEventListener('popstate', syncFromUrl); |
| 1428 | 1428 | window.addEventListener('stx:navigate', syncFromUrl); |
| 1429 | onDestroy(function() { | |
| 1430 | window.removeEventListener('popstate', syncFromUrl); | |
| 1431 | window.removeEventListener('stx:navigate', syncFromUrl); | |
| 1432 | }); | |
| 1429 | 1433 | return { |
| 1430 | 1434 | data: params, |
| 1431 | 1435 | get: function(key) { return params()[key]; }, |
| @@ -1449,6 +1453,14 @@ else { | ||
| 1449 | 1453 | // ========================================================================== |
| 1450 | 1454 | |
| 1451 | 1455 | 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 | } | |
| 1452 | 1464 | |
| 1453 | 1465 | function useQuery(url, options) { |
| 1454 | 1466 | options = options || {}; |
| @@ -1492,6 +1504,8 @@ else { | ||
| 1492 | 1504 | data.set(transformed); |
| 1493 | 1505 | isStale.set(false); |
| 1494 | 1506 | _queryCache[key] = { data: transformed, timestamp: Date.now() }; |
| 1507 | if (_queryCacheKeys.indexOf(key) === -1) _queryCacheKeys.push(key); | |
| 1508 | _evictQueryCache(); | |
| 1495 | 1509 | if (options.onSuccess) options.onSuccess(transformed); |
| 1496 | 1510 | // Schedule cache eviction |
| 1497 | 1511 | setTimeout(function() { delete _queryCache[key]; }, cacheTime); |
| @@ -1924,7 +1938,13 @@ else if (name === '@text' || name === ':text') { | ||
| 1924 | 1938 | } |
| 1925 | 1939 | else if (name === '@html' || name === ':html') { |
| 1926 | 1940 | 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; | |
| 1928 | 1948 | }); |
| 1929 | 1949 | el.removeAttribute(name); |
| 1930 | 1950 | } |