- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: php-security/laravel-native-sql-injection
Language: PHP
Severity: Error
Category: Security
CWE: 89
SQL injection is a code injection technique that attackers use to exploit vulnerabilities in a web application’s database layer. This can lead to unauthorized access, data theft, data loss, and even loss of control over the server.
SQL injection vulnerabilities are among the most common and most harmful security flaws in web applications. These vulnerabilities can lead to severe consequences, including data breaches and unauthorized access to sensitive data.
Do not concatenate strings to form SQL queries; instead, use parameterized queries or prepared statements. Concatenating strings can lead to SQL injection if the inputs are not properly sanitized.
<?php
class UserController extends Controller
{
public function show($userId) {
$query = 'SELECT * FROM users WHERE id = ' . $userId;
$result = dbx_query($connection, $query);
return view('user.show', ['users' => $result]);
}
public function display($userId) {
$connection = db2_connect($dbName, $dbUser, $dbPass);
$sql = 'SELECT * FROM users WHERE id = ' . $userId;
$result = db2_exec($connection, $sql);
return view('user.show', ['users' => $result]);
}
public function findByEmail($email) {
$query = 'SELECT * FROM users WHERE email = ' . $email;
$result = mysql_unbuffered_query($query, $connection);
return view('user.show', ['users' => $result]);
}
}
<?php
class UserController extends Controller
{
public function show($userId) {
$result = DB::table('users')->where('id', $userId)->get();
return view('user.show', ['users' => $result]);
}
public function display($userId) {
$connection = db2_connect($dbName, $dbUser, $dbPass);
$sql = 'SELECT * FROM users WHERE id = ?';
$stmt = db2_prepare($connection, $sql);
db2_bind_param($stmt, 1, "userId", DB2_PARAM_IN);
db2_execute($stmt);
$result = db2_fetch_assoc($stmt);
return view('user.show', ['users' => $result]);
}
public function findByEmail($email) {
$result = DB::table('users')->where('email', $email)->get();
return view('user.show', ['users' => $result]);
}
}