베타 Shoulder는 베타 버전입니다 — 결과가 가끔 잘못될 수 있습니다. 여러분의 피드백이 다음에 무엇을 고칠지 결정합니다. 피드백 공유
🔄

Cross-Site Request Forgery (CSRF)

🛡️ 3 개의 규칙이 이를 탐지합니다

Cross-Site Request Forgery (CSRF)

The web application does not, or can not, sufficiently verify whether a well-formed, valid, consistent request was intentionally provided by the user who submitted the request.

When a web server is designed to receive a request from a client without any mechanism for verifying that it was intentionally sent, then it might be possible for an attacker to trick a client into making an unintentional request to the web server which will be treated as an authentic request.

보급률
보통
3개 언어 지원
영향
높음
3개의 높은 심각도 규칙
예방
문서화됨
3개의 수정 예시
2 예방
2 예방

이 취약점을 수정하는 방법

3개의 Shoulder 탐지 규칙을 기반으로 한 Cross-Site Request Forgery 예방 전략.

Angular Missing HTTP Security Interceptor HIGH

Create HTTP interceptors to centralize authentication tokens and CSRF protection across all requests

+21 -22 javascript
- import { HttpClient } from '@angular/common/http';
- import { Injectable } from '@angular/core';
- 
- @Injectable({ providedIn: 'root' })
- export class UserService {
-   constructor(private http: HttpClient) {}
- 
-   getUsers() {
-     return this.http.get('/api/users', {
-       headers: { Authorization: `Bearer ${this.getToken()}` }
-     });
-   }
- 
-   updateUser(id: string, data: any) {
-     // Easy to forget auth header on new endpoints
-     return this.http.put(`/api/users/${id}`, data);
-   }
- 
-   private getToken(): string {
-     return localStorage.getItem('token') || '';
-   }
- }
+ import { Injectable } from '@angular/core';
+ import { HttpInterceptor, HttpRequest, HttpHandler, HTTP_INTERCEPTORS } from '@angular/common/http';
+ import { AuthService } from './auth.service';
+ 
+ @Injectable()
+ export class AuthInterceptor implements HttpInterceptor {
+   constructor(private auth: AuthService) {}
+ 
+   intercept(req: HttpRequest<any>, next: HttpHandler) {
+     const token = this.auth.getToken();
+     if (token) {
+       req = req.clone({
+         headers: req.headers.set('Authorization', `Bearer ${token}`)
+       });
+     }
+     return next.handle(req);
+   }
+ }
+ 
+ // In app.module.ts
+ // providers: [{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }]
  
Django Missing CSRF Protection HIGH

Ensure CsrfViewMiddleware is enabled and never use @csrf_exempt on state-changing views

+4 -4 python
- from django.views.decorators.csrf import csrf_exempt
- from django.http import JsonResponse
- 
- @csrf_exempt
+ from django.views.decorators.csrf import csrf_protect
+ from django.http import JsonResponse
+ 
+ @csrf_protect
  def transfer_funds(request):
      amount = request.POST['amount']
      recipient = request.POST['recipient']
      process_transfer(request.user, recipient, amount)
      return JsonResponse({'status': 'transferred'})
  
Missing CSRF Protection (Gin) HIGH

Add CSRF middleware to protect state-changing endpoints

+11 -4 go
  package main
  
- import "github.com/gin-gonic/gin"
- 
- func main() {
-     r := gin.Default()
+ import (
+     "os"
+     "github.com/gin-gonic/gin"
+     "github.com/utrack/gin-csrf"
+ )
+ 
+ func main() {
+     r := gin.Default()
+     r.Use(csrf.Middleware(csrf.Options{
+         Secret: os.Getenv("CSRF_SECRET"),
+     }))
      r.POST("/transfer", transferMoney)
      r.Run(":8080")
  }
  
4 경고 신호
4 경고 신호

코드 리뷰에서 주의할 점

이 패턴은 잠재적인 Cross-Site Request Forgery (CSRF) 취약점을 나타냅니다. 코드 리뷰와 보안 감사 중에 찾아보세요.

🟠
HttpClient used without security interceptors. Missing centralized authentication, CSRF protection, and security headers angular-http-interceptor-missing
🟠
View handles POST/PUT/DELETE without @csrf_protect or @ensure_csrf_cookie decorator django-missing-csrf-protection
🟠
Django views that handle POST/PUT/DELETE requests without CSRF protection django-missing-csrf-protection
🟠
State-changing endpoints lack CSRF protection go-gin-missing-csrf-protection
🔍

코드베이스를 스캔하세요: Cross-Site Request Forgery (CSRF)

Shoulder CLI는 전체 코드베이스에서 취약한 패턴을 찾아냅니다.