refactor(misc): Harden request handling, tighten defaults, and pin CI deps (#2878)

* refactor(misc): Harden request handling, tighten defaults, and pin CI dependencies

* feat(auth): normalize usernames for login rate limiting

* refactor(epub): fix XML document builder creation

* feat(http): enhance image download with redirect handling and DNS rebinding protection

* chore: upgrade Node.js version to 24 and add frontend dependency audit step

* feat(auth): refactor username normalization for login rate limiting and enhance image download security

* fix(metadata): simplify JAXB validation event handling by using direct import

* chore(pipeline): remove unnecessary --force flag from npm ci and format audit step

* chore(pipeline): streamline frontend dependency audits and add validation step

* fix(image): improve error handling for image processing and download, enforce pixel limits

* test(image): update tests

* fix(icon): update DOMPurify import and replace deprecated theme package

* fix(imports): update theme package imports and format code for consistency

* fix(cors): update allowed origins configuration to support wildcard and trim whitespace
This commit is contained in:
Balázs Szücs
2026-02-24 12:43:14 -07:00
committed by GitHub
parent 161c675f74
commit f3fffeadce
31 changed files with 989 additions and 626 deletions
@@ -1,10 +1,11 @@
import {inject, Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable, of} from 'rxjs';
import {finalize, map, shareReplay, tap} from 'rxjs/operators';
import {API_CONFIG} from '../../core/config/api-config';
import {IconCacheService} from './icon-cache.service';
import {DomSanitizer, SafeHtml} from '@angular/platform-browser';
import { inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { finalize, map, shareReplay, tap } from 'rxjs/operators';
import { API_CONFIG } from '../../core/config/api-config';
import { IconCacheService } from './icon-cache.service';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import DOMPurify from 'dompurify';
interface SvgIconData {
svgName: string;
@@ -25,7 +26,6 @@ interface SvgIconBatchResponse {
}
type IconContentMap = Record<string, string>;
@Injectable({
providedIn: 'root'
})
@@ -39,6 +39,16 @@ export class IconService {
private iconCache = inject(IconCacheService);
private sanitizer = inject(DomSanitizer);
/**
* Sanitizes SVG content using DOMPurify.
*/
private sanitizeSvgContent(content: string): string {
return DOMPurify.sanitize(content, {
USE_PROFILES: { svg: true },
FORBID_TAGS: ['script', 'style', 'foreignObject']
});
}
preloadAllIcons(): Observable<void> {
if (this.preloadCache$) {
return this.preloadCache$;
@@ -47,12 +57,12 @@ export class IconService {
this.preloadCache$ = this.http.get<IconContentMap>(`${this.baseUrl}/all/content`).pipe(
tap((iconsMap) => {
Object.entries(iconsMap).forEach(([iconName, content]) => {
const sanitized = this.sanitizer.bypassSecurityTrustHtml(content);
const sanitized = this.sanitizer.bypassSecurityTrustHtml(this.sanitizeSvgContent(content));
this.iconCache.cacheIcon(iconName, content, sanitized);
});
}),
map(() => void 0),
shareReplay({bufferSize: 1, refCount: false}),
shareReplay({ bufferSize: 1, refCount: false }),
finalize(() => this.preloadCache$ = null)
);
@@ -70,10 +80,10 @@ export class IconService {
responseType: 'text'
}).pipe(
tap(content => {
const sanitized = this.sanitizer.bypassSecurityTrustHtml(content);
const sanitized = this.sanitizer.bypassSecurityTrustHtml(this.sanitizeSvgContent(content));
this.iconCache.cacheIcon(iconName, content, sanitized);
}),
shareReplay({bufferSize: 1, refCount: true}),
shareReplay({ bufferSize: 1, refCount: true }),
finalize(() => this.requestCache.delete(iconName))
);
@@ -113,13 +123,13 @@ export class IconService {
}
saveBatchSvgIcons(icons: SvgIconData[]): Observable<SvgIconBatchResponse> {
return this.http.post<SvgIconBatchResponse>(`${this.baseUrl}/batch`, {icons}).pipe(
return this.http.post<SvgIconBatchResponse>(`${this.baseUrl}/batch`, { icons }).pipe(
tap((response) => {
response.results.forEach(result => {
if (result.success) {
const iconData = icons.find(icon => icon.svgName === result.iconName);
if (iconData) {
const sanitized = this.sanitizer.bypassSecurityTrustHtml(iconData.svgData);
const sanitized = this.sanitizer.bypassSecurityTrustHtml(this.sanitizeSvgContent(iconData.svgData));
this.iconCache.cacheIcon(iconData.svgName, iconData.svgData, sanitized);
}
}