Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Remove remote class from HTML

Chocobozzzdff2e95369db
diff --git a/client/src/app/+videos/+video-watch/shared/comment/video-comment.component.scss b/client/src/app/+videos/+video-watch/shared/comment/video-comment.component.scss
index 3175dc2b59..3671843aff 100644
--- a/client/src/app/+videos/+video-watch/shared/comment/video-comment.component.scss
+++ b/client/src/app/+videos/+video-watch/shared/comment/video-comment.component.scss
@@ -97,17 +97,12 @@
.comment-html {
@include peertube-word-wrap;
- // Mentions
::ng-deep a {
+ color: pvar(--fg);
- &:not(.linkified-url) {
- color: pvar(--fg);
-
- font-weight: $font-semibold;
-
- @include disable-default-a-behaviour;
- }
+ font-weight: $font-semibold;
+ @include disable-default-a-behaviour;
}
// Paragraphs
diff --git a/client/src/app/core/renderer/html-renderer.service.ts b/client/src/app/core/renderer/html-renderer.service.ts
index 75a23192f8..e3888b4463 100644
--- a/client/src/app/core/renderer/html-renderer.service.ts
+++ b/client/src/app/core/renderer/html-renderer.service.ts
@@ -22,7 +22,7 @@ export class HtmlRendererService {
this.addHrefHook(this.enhancedDomPurify)
this.addCheckSchemesHook(this.simpleDomPurify, getDefaultSanitizedSchemes())
- this.addCheckSchemesHook(this.simpleDomPurify, [ ...getDefaultSanitizedSchemes(), 'mailto' ])
+ this.addCheckSchemesHook(this.enhancedDomPurify, [ ...getDefaultSanitizedSchemes(), 'mailto' ])
}
private addHrefHook (dompurifyInstance: DOMPurifyI) {
@@ -72,8 +72,17 @@ export class HtmlRendererService {
})
}
+ removeClassAttributes (html: string) {
+ return DOMPurify().sanitize(html, {
+ ALLOWED_TAGS: getDefaultSanitizedTags(),
+ ALLOWED_ATTR: getDefaultSanitizedHrefAttributes().filter(a => a !== 'class'),
+ ALLOW_DATA_ATTR: true
+ })
+ }
+
async toSimpleSafeHtml (text: string) {
- const html = await this.linkifier.linkify(text)
+ let html = this.removeClassAttributes(text)
+ html = await this.linkifier.linkify(html)
return this.sanitize(this.simpleDomPurify, html)
}
diff --git a/client/src/app/core/renderer/linkifier.service.ts b/client/src/app/core/renderer/linkifier.service.ts
index 5c99722f6e..0a8bfa75e5 100644
--- a/client/src/app/core/renderer/linkifier.service.ts
+++ b/client/src/app/core/renderer/linkifier.service.ts
@@ -1,17 +1,18 @@
import { Injectable } from '@angular/core'
import { getAbsoluteAPIUrl } from '@app/helpers/utils'
-import * as LinkifyJS from 'linkifyjs'
+import type * as LinkifyJS from 'linkifyjs'
+import type LinkifyHTML from 'linkify-html'
@Injectable()
export class LinkifierService {
static CLASSNAME = 'linkified'
private linkifyModule: typeof LinkifyJS
- private linkifyHtmlModule: any
+ private linkifyHtmlModule: typeof LinkifyHTML
private mentionPluginInitialized = false
- private linkifyOptions = {
+ private linkifyOptions: LinkifyJS.Opts = {
className: {
mention: LinkifierService.CLASSNAME + '-mention',
url: LinkifierService.CLASSNAME + '-url'