File tree Expand file tree Collapse file tree
app/service/service_worker Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,7 +21,6 @@ import { FaviconDAO } from "@App/app/repo/favicon";
2121import { onRegularUpdateCheckAlarm } from "./regular_updatecheck" ;
2222import { cacheInstance } from "@App/app/cache" ;
2323import { InfoNotification } from "./utils" ;
24- import { sanitizeHTML } from "@App/pkg/utils/sanitize" ;
2524
2625// service worker的管理器
2726export default class ServiceWorkerManager {
@@ -116,7 +115,7 @@ export default class ServiceWorkerManager {
116115 . then ( ( resp : { data : { [ key : string ] : any ; notice : string ; version : string } } ) => {
117116 const data = resp . data ;
118117 systemConfig
119- . getCheckUpdate ( { sanitizeHTML } )
118+ . getCheckUpdate ( )
120119 . then ( ( items ) => {
121120 const isRead = items . notice !== data . notice ? false : items . isRead ;
122121 systemConfig . setCheckUpdate ( { ...data , isRead : isRead } ) ;
Original file line number Diff line number Diff line change @@ -271,9 +271,12 @@ function App() {
271271 const checkScriptEnableAndUpdate = async ( ) => {
272272 const [ isEnableScript , checkUpdate ] = await Promise . all ( [
273273 systemConfig . getEnableScript ( ) ,
274- systemConfig . getCheckUpdate ( { sanitizeHTML } ) ,
274+ systemConfig . getCheckUpdate ( ) ,
275275 ] ) ;
276276 if ( ! hookMgr . isMounted ) return ;
277+ if ( typeof checkUpdate . notice === "string" ) {
278+ checkUpdate . notice = sanitizeHTML ( checkUpdate . notice ) ;
279+ }
277280 setIsEnableScript ( isEnableScript ) ;
278281 setCheckUpdate ( checkUpdate ) ;
279282 } ;
Original file line number Diff line number Diff line change 11import DOMPurify from "dompurify" ;
22
33// 允许的安全 CSS 属性白名单
4- const ALLOWED_CSS_PROPERTIES = [ "color" , "font-size" , "font-weight" , "font-style" ] ;
4+ const ALLOWED_CSS_PROPERTIES = new Set ( [ "color" , "font-size" , "font-weight" , "font-style" ] ) ;
55
66// 过滤不安全的 CSS 属性,只保留白名单中的属性
77DOMPurify . addHook ( "afterSanitizeAttributes" , ( node ) => {
88 if ( node instanceof HTMLElement && node . hasAttribute ( "style" ) ) {
99 const { style } = node ;
1010 for ( let i = style . length - 1 ; i >= 0 ; i -- ) {
11- if ( ! ALLOWED_CSS_PROPERTIES . includes ( style [ i ] ) ) {
11+ if ( ! ALLOWED_CSS_PROPERTIES . has ( style [ i ] ) ) {
1212 style . removeProperty ( style [ i ] ) ;
1313 }
1414 }
You can’t perform that action at this time.
0 commit comments