mirror of https://github.com/ghostfolio/ghostfolio
Browse Source
* Add rate limiting to authentication and sign up endpoints * Update changelogpull/7294/head
committed by
GitHub
16 changed files with 259 additions and 51 deletions
@ -0,0 +1,21 @@ |
|||||
|
import { ExecutionContext, Injectable, Logger } from '@nestjs/common'; |
||||
|
import { ThrottlerException, ThrottlerGuard } from '@nestjs/throttler'; |
||||
|
|
||||
|
@Injectable() |
||||
|
export class CustomThrottlerGuard extends ThrottlerGuard { |
||||
|
private readonly logger = new Logger(CustomThrottlerGuard.name); |
||||
|
|
||||
|
public async canActivate(context: ExecutionContext): Promise<boolean> { |
||||
|
try { |
||||
|
return await super.canActivate(context); |
||||
|
} catch (error) { |
||||
|
if (error instanceof ThrottlerException) { |
||||
|
throw error; |
||||
|
} |
||||
|
|
||||
|
this.logger.error(error); |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; |
||||
|
|
||||
|
export function getRedisConnectionOptions( |
||||
|
configurationService: ConfigurationService |
||||
|
) { |
||||
|
return { |
||||
|
db: configurationService.get('REDIS_DB'), |
||||
|
host: configurationService.get('REDIS_HOST'), |
||||
|
password: configurationService.get('REDIS_PASSWORD'), |
||||
|
port: configurationService.get('REDIS_PORT') |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
export function getRedisConnectionUrl( |
||||
|
configurationService: ConfigurationService |
||||
|
): string { |
||||
|
const { db, host, password, port } = |
||||
|
getRedisConnectionOptions(configurationService); |
||||
|
const encodedPassword = encodeURIComponent(password); |
||||
|
|
||||
|
return `redis://${encodedPassword ? `:${encodedPassword}` : ''}@${host}:${port}/${db}`; |
||||
|
} |
||||
Loading…
Reference in new issue