/
goncharovchik
/
secure-api-d
Обзор
Документация
Войти
/
goncharovchik
/
secure-api-d
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
insecure
src/modules/bots/bots.controller.ts
89 строк
3 KB
Aleksey Goncharov
feat: insecure API — intentionally vulnerable (no auth, no validation, SQL injection, plain text passwords)
29 апр 2026, 12:02
29 апр 2026, 12:02
651dea3
Код
Авторство
О чём код?
import { Controller, Get, Post, Patch, Delete, Body, Param, Query, } from '@nestjs/common'; import { ApiTags, ApiOperation, ApiQuery } from '@nestjs/swagger'; import { BotsService } from './bots.service'; import { CreateBotDto } from './dto/create-bot.dto'; import { UpdateBotDto } from './dto/update-bot.dto'; /** * Контроллер ботов. * INSECURE: * - Нет аутентификации — доступ без токена * - Нет RBAC — любой пользователь * - Нет IDOR protection — видны чужие боты * - Нет валидации входных данных * - SQL Injection в поиске */ @ApiTags('Bots') @Controller('api/bots') export class BotsController { constructor(private readonly botsService: BotsService) {} /** INSECURE: нет авторизации, нет валидации */ @Post() @ApiOperation({ summary: 'Создать бота' }) create(@Body() dto: CreateBotDto) { return this.botsService.create(dto); } /** INSECURE: без токена → 200, без пагинации */ @Get() @ApiOperation({ summary: 'Получить всех ботов' }) findAll() { return this.botsService.findAll(); } /** * INSECURE: SQL Injection через параметр name. * Пример: GET /api/bots/search?name=' OR 1=1 -- */ @Get('search') @ApiOperation({ summary: 'Поиск ботов по имени (SQL Injection!)' }) @ApiQuery({ name: 'name', required: true }) search(@Query('name') name: string) { return this.botsService.search(name); } /** INSECURE: любой видит любого бота (IDOR) */ @Get(':id') @ApiOperation({ summary: 'Получить бота по ID' }) findOne(@Param('id') id: string) { return this.botsService.findOne(+id); } /** INSECURE: любой может изменить чужого бота */ @Patch(':id') @ApiOperation({ summary: 'Обновить бота' }) update(@Param('id') id: string, @Body() dto: UpdateBotDto) { return this.botsService.update(+id, dto); } /** INSECURE: любой может удалить чужого бота */ @Delete(':id') @ApiOperation({ summary: 'Удалить бота' }) remove(@Param('id') id: string) { return this.botsService.remove(+id); } /** Запустить бота */ @Post(':id/start') @ApiOperation({ summary: 'Запустить бота' }) start(@Param('id') id: string) { return this.botsService.start(+id); } /** Остановить бота */ @Post(':id/stop') @ApiOperation({ summary: 'Остановить бота' }) stop(@Param('id') id: string) { return this.botsService.stop(+id); } }