Browse Source
Task/validate and encode URL in logo endpoint (#7330)
* Harden URL validation in logo endpoint
* Update changelog
pull/7340/head
Thomas Kaul
11 hours ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with
14 additions and
3 deletions
-
CHANGELOG.md
-
apps/api/src/app/logo/get-logo.dto.ts
-
apps/api/src/app/logo/logo.controller.ts
-
apps/api/src/app/logo/logo.service.ts
-
libs/ui/src/lib/entity-logo/entity-logo-image-source.service.ts
|
|
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 |
|
|
|
|
|
|
|
|
### Changed |
|
|
### Changed |
|
|
|
|
|
|
|
|
|
|
|
- Hardened the validation of the URL in the logo endpoint |
|
|
- Set the change detection strategy to `OnPush` in the about pages |
|
|
- Set the change detection strategy to `OnPush` in the about pages |
|
|
- Set the change detection strategy to `OnPush` in the accounts page |
|
|
- Set the change detection strategy to `OnPush` in the accounts page |
|
|
- Set the change detection strategy to `OnPush` in the demo page |
|
|
- Set the change detection strategy to `OnPush` in the demo page |
|
|
|
|
|
@ -0,0 +1,9 @@ |
|
|
|
|
|
import { IsUrl } from 'class-validator'; |
|
|
|
|
|
|
|
|
|
|
|
export class GetLogoDto { |
|
|
|
|
|
@IsUrl({ |
|
|
|
|
|
protocols: ['http', 'https'], |
|
|
|
|
|
require_protocol: true |
|
|
|
|
|
}) |
|
|
|
|
|
url: string; |
|
|
|
|
|
} |
|
|
@ -12,6 +12,7 @@ import { |
|
|
import { DataSource } from '@prisma/client'; |
|
|
import { DataSource } from '@prisma/client'; |
|
|
import { Response } from 'express'; |
|
|
import { Response } from 'express'; |
|
|
|
|
|
|
|
|
|
|
|
import { GetLogoDto } from './get-logo.dto'; |
|
|
import { LogoService } from './logo.service'; |
|
|
import { LogoService } from './logo.service'; |
|
|
|
|
|
|
|
|
@Controller('logo') |
|
|
@Controller('logo') |
|
|
@ -41,7 +42,7 @@ export class LogoController { |
|
|
|
|
|
|
|
|
@Get() |
|
|
@Get() |
|
|
public async getLogoByUrl( |
|
|
public async getLogoByUrl( |
|
|
@Query('url') url: string, |
|
|
@Query() { url }: GetLogoDto, |
|
|
@Res() response: Response |
|
|
@Res() response: Response |
|
|
) { |
|
|
) { |
|
|
try { |
|
|
try { |
|
|
|
|
|
@ -47,7 +47,7 @@ export class LogoService { |
|
|
private async getBuffer(aUrl: string) { |
|
|
private async getBuffer(aUrl: string) { |
|
|
const blob = await this.fetchService |
|
|
const blob = await this.fetchService |
|
|
.fetch( |
|
|
.fetch( |
|
|
`https://t0.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=${aUrl}&size=64`, |
|
|
`https://t0.gstatic.com/faviconV2?client=SOCIAL&fallback_opts=TYPE,SIZE,URL&size=64&type=FAVICON&url=${encodeURIComponent(aUrl)}`, |
|
|
{ |
|
|
{ |
|
|
headers: { 'User-Agent': 'request' }, |
|
|
headers: { 'User-Agent': 'request' }, |
|
|
signal: AbortSignal.timeout( |
|
|
signal: AbortSignal.timeout( |
|
|
|
|
|
@ -15,6 +15,6 @@ export class EntityLogoImageSourceService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public getLogoUrlByUrl(url: string) { |
|
|
public getLogoUrlByUrl(url: string) { |
|
|
return `../api/v1/logo?url=${url}`; |
|
|
return `../api/v1/logo?url=${encodeURIComponent(url)}`; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|