Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(docs-hyper-link-ui): add isSafeUrl check before opening hyperlink (#6993)

白熱88d0a8f89bf9
diff --git a/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts b/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts
index 7fc0cb1106..74fde1542f 100644
--- a/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts
+++ b/packages/docs-hyper-link-ui/src/commands/operations/popup.operation.ts
@@ -15,7 +15,7 @@
*/
import type { DocumentDataModel, IAccessor, ICommand } from '@univerjs/core';
-import { CommandType, CustomRangeType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import { CommandType, CustomRangeType, isSafeUrl, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { DocHyperLinkPopupService } from '../../services/hyper-link-popup.service';
@@ -104,9 +104,10 @@ export const ClickDocHyperLinkOperation: ICommand<{ unitId: string; linkId: stri
const body = doc?.getSelfOrHeaderFooterModel(segmentId).getBody();
const link = body?.customRanges?.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK)?.properties?.url;
- if (link) {
- window.open(link, '_blank', 'noopener noreferrer');
+ if (!isSafeUrl(link)) {
+ return false;
}
+ window.open(link, '_blank', 'noopener noreferrer');
return true;
},
};