Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
fix(frontend:select): prevent XSS in highlighted options
johavenbd1e89a45b14
diff --git a/frontend/package.json b/frontend/package.jsonindex 154f9ef8..a208503b 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -50,6 +50,7 @@"angular-l10n": "^17.0.1","codemirror": "^6.0.2","dayjs": "^1.11.21",+ "entities": "^8.0.0","ngx-bootstrap": "^21.2.0","ngx-clipboard": "^16.0.0","ngx-socket-io": "4.10.0",diff --git a/frontend/src/app/common/components/select/select.component.html b/frontend/src/app/common/components/select/select.component.htmlindex 516e5eb6..f8120bd5 100644--- a/frontend/src/app/common/components/select/select.component.html+++ b/frontend/src/app/common/components/select/select.component.html@@ -63,9 +63,9 @@<fa-icon [icon]="itemIcon" [fixedWidth]="false"></fa-icon></span><div class="d-flex flex-column text-truncate">- <span class="text-truncate" [innerHtml]="sanitize(o.name | highlight:i)"></span>+ <span class="text-truncate" [innerHTML]="o.name | highlight:i"></span>@if (o.description) {- <span class="text-truncate fs-xs text-muted" [innerHtml]="sanitize(o.description | highlight:i)"></span>+ <span class="text-truncate fs-xs text-muted" [innerHTML]="o.description | highlight:i"></span>}</div></div>diff --git a/frontend/src/app/common/components/select/select.component.ts b/frontend/src/app/common/components/select/select.component.tsindex db55cc0a..2db3daf4 100644--- a/frontend/src/app/common/components/select/select.component.ts+++ b/frontend/src/app/common/components/select/select.component.ts@@ -1,7 +1,6 @@import { NgTemplateOutlet } from '@angular/common'import { Component, ElementRef, EventEmitter, forwardRef, inject, Input, OnDestroy, OnInit, Output, TemplateRef } from '@angular/core'import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'-import { DomSanitizer, SafeHtml } from '@angular/platform-browser'import { FaIconComponent } from '@fortawesome/angular-fontawesome'import { IconDefinition } from '@fortawesome/fontawesome-svg-core'import { faQuestion, faXmark } from '@fortawesome/free-solid-svg-icons'@@ -48,7 +47,6 @@ export class SelectComponent implements OnInit, OnDestroy, ControlValueAccessorpublic inputValue = ''protected onChange: any = Function.prototypeprotected onTouched: any = Function.prototype- private readonly sanitizer = inject(DomSanitizer)private subscription: Subscriptionprivate behavior: GenericBehavior@@ -128,10 +126,6 @@ export class SelectComponent implements OnInit, OnDestroy, ControlValueAccessor}}- public sanitize(html: string): SafeHtml {- return this.sanitizer.bypassSecurityTrustHtml(html)- }-public inputEvent(e: any, isUpMode = false) {// tabif (e.keyCode === 9) {diff --git a/frontend/src/app/common/pipes/highlight.pipe.ts b/frontend/src/app/common/pipes/highlight.pipe.tsindex 07450257..b197bddd 100644--- a/frontend/src/app/common/pipes/highlight.pipe.ts+++ b/frontend/src/app/common/pipes/highlight.pipe.ts@@ -1,21 +1,22 @@import { Pipe, PipeTransform } from '@angular/core'+import { escapeUTF8 } from 'entities/escape'@Pipe({ name: 'highlight' })export class HighlightPipe implements PipeTransform {- transform(text: string, search: string, reset = false): string {- if (reset && search.length < 1) {- return text- }- if (search && text) {- let pattern = search.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&')- pattern = pattern- .split(' ')- .filter((t) => t.length > 0)- .join('|')- const regex = new RegExp(pattern, 'gi')- return text.replace(regex, (match) => `<b>${match}</b>`)- } else {- return text+ transform(text: string, search: string): string {+ const sourceText = text || ''+ const pattern = (search || '')+ .replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&')+ .split(' ')+ .filter((term) => term.length > 0)+ .join('|')+ if (!pattern) {+ return escapeUTF8(sourceText)}++ return sourceText+ .split(new RegExp(`(${pattern})`, 'gi'))+ .map((part, index) => (index % 2 ? `<b>${escapeUTF8(part)}</b>` : escapeUTF8(part)))+ .join('')}}diff --git a/package-lock.json b/package-lock.jsonindex 880e35ff..52b077b0 100644--- a/package-lock.json+++ b/package-lock.json@@ -172,6 +172,7 @@"angular-l10n": "^17.0.1","codemirror": "^6.0.2","dayjs": "^1.11.21",+ "entities": "^8.0.0","ngx-bootstrap": "^21.2.0","ngx-clipboard": "^16.0.0","ngx-socket-io": "4.10.0",