Skip to content

Commit 8ab4d71

Browse files
committed
Fixes code scanning alerts
Signed-off-by: Daniel Kastl <[email protected]>
1 parent 5774810 commit 8ab4d71

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,20 @@
2222
"dependencies": {
2323
"@juggle/resize-observer": "^3.4.0",
2424
"@mdi/font": "^7.4.47",
25+
"dompurify": "^3.1.5",
2526
"fontfaceobserver": "^2.3.0",
2627
"geojson": "^0.5.0",
2728
"ol": "^9.1.0",
2829
"ol-ext": "^4.0.15",
2930
"ol-mapbox-style": "^12.3.4"
3031
},
3132
"devDependencies": {
33+
"@types/dompurify": "^3.0.5",
3234
"@types/fontfaceobserver": "^2.1.3",
3335
"@types/geojson": "^7946.0.14",
36+
"@types/google.maps": "^3.55.11",
3437
"@types/jquery": "^3.5.30",
3538
"@types/jqueryui": "^1.12.23",
36-
"@types/google.maps": "^3.55.11",
3739
"@types/ol-ext": "npm:@siedlerchr/types-ol-ext",
3840
"css-loader": "^7.1.2",
3941
"sass": "^1.77.6",

src/components/gtt-client/init/controls.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Target from 'ol-ext/control/Target';
88
import Hover from 'ol-ext/interaction/Hover';
99
import Notification from 'ol-ext/control/Notification';
1010
import { position } from 'ol-ext/control/control';
11+
import DOMPurify from 'dompurify';
1112

1213
import { radiansToDegrees, degreesToRadians, parseHistory, formatLength, formatArea } from "../helpers";
1314
import { zoomToExtent, setGeolocation, setView, setControls, setPopover } from "../openlayers";
@@ -43,7 +44,8 @@ function setSearchControl(instance: any): void {
4344
// Add copy to clipboard functionality, if available
4445
if (navigator.clipboard) {
4546
// strip htmls from response title
46-
const text = response.title.replace(/<[^>]*>?/gm, '');
47+
const sanitizedTitle = DOMPurify.sanitize(response.title, { ALLOWED_TAGS: [] });
48+
const text = sanitizedTitle.replace(/<[^>]*>?/gm, '');
4749
navigator.clipboard.writeText(text);
4850
instance.map.notification.show(instance.i18n.control.copied_location_to_clipboard);
4951
}

src/components/gtt-client/openlayers/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,22 @@ export function setPopover() {
443443
template: {
444444
title: (ftr: any) => {
445445
const popup_contents = JSON.parse(this.contents.popup);
446-
const url = popup_contents.href.replace(/\[(.+?)\]/g, ftr.get('id'));
447446
const subject = ftr.get('subject');
448447
const displaySubject = subject.length > 25 ? `${subject.substring(0, 22)}…` : subject;
448+
449+
const replacePlaceholders = (str: string, replacement: string): string => {
450+
return str.split('[').map(part => {
451+
const endIndex = part.indexOf(']');
452+
if (endIndex !== -1) {
453+
return replacement + part.substring(endIndex + 1);
454+
}
455+
return part;
456+
}).join('');
457+
};
458+
459+
const url = replacePlaceholders(popup_contents.href, ftr.get('id'));
449460
return `${displaySubject} <a href="${url}"><i class="mdi mdi-arrow-right-circle-outline"></i></a>`;
450-
},
461+
},
451462
attributes: {}
452463
}
453464
});

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// "esModuleInterop": true,
1313
// "skipLibCheck": true,
1414
// "sourceMap": true,
15+
"allowSyntheticDefaultImports": true,
1516
"paths": {
1617
"*": ["@types/*"]
1718
}

yarn.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@
109109
resolved "https://registry.npmjs.org/@petamoriken/float16/-/float16-3.8.0.tgz"
110110
integrity sha512-AhVAm6SQ+zgxIiOzwVdUcDmKlu/qU39FiYD2UD6kQQaVenrn0dGZewIghWAENGQsvC+1avLCuT+T2/3Gsp/W3w==
111111

112+
"@types/dompurify@^3.0.5":
113+
version "3.0.5"
114+
resolved "https://registry.yarnpkg.com/@types/dompurify/-/dompurify-3.0.5.tgz#02069a2fcb89a163bacf1a788f73cb415dd75cb7"
115+
integrity sha512-1Wg0g3BtQF7sSb27fJQAKck1HECM6zV1EB66j8JH9i3LCjYabJa0FSdiSgsD5K/RbrsR0SiraKacLB+T8ZVYAg==
116+
dependencies:
117+
"@types/trusted-types" "*"
118+
112119
"@types/eslint-scope@^3.7.3":
113120
version "3.7.4"
114121
resolved "https://registry.npmjs.org/@types/eslint-scope/-/eslint-scope-3.7.4.tgz"
@@ -191,6 +198,11 @@
191198
resolved "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.3.tgz"
192199
integrity sha512-JYM8x9EGF163bEyhdJBpR2QX1R5naCJHC8ucJylJ3w9/CVBaskdQ8WqBf8MmQrd1kRvp/a4TS8HJ+bxzR7ZJYQ==
193200

201+
"@types/trusted-types@*":
202+
version "2.0.7"
203+
resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.7.tgz#baccb07a970b91707df3a3e8ba6896c57ead2d11"
204+
integrity sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==
205+
194206
"@webassemblyjs/[email protected]", "@webassemblyjs/ast@^1.12.1":
195207
version "1.12.1"
196208
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.12.1.tgz#bb16a0e8b1914f979f45864c23819cc3e3f0d4bb"
@@ -531,6 +543,11 @@ cssesc@^3.0.0:
531543
resolved "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz"
532544
integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==
533545

546+
dompurify@^3.1.5:
547+
version "3.1.5"
548+
resolved "https://registry.yarnpkg.com/dompurify/-/dompurify-3.1.5.tgz#2c6a113fc728682a0f55684b1388c58ddb79dc38"
549+
integrity sha512-lwG+n5h8QNpxtyrJW/gJWckL+1/DQiYMX8f7t8Z2AZTPw1esVrqjI63i7Zc2Gz0aKzLVMYC1V1PL/ky+aY/NgA==
550+
534551
earcut@^2.2.3:
535552
version "2.2.4"
536553
resolved "https://registry.npmjs.org/earcut/-/earcut-2.2.4.tgz"

0 commit comments

Comments
 (0)