Skip to content

Commit

Permalink
Resolução SQL Injection [Issue #857]
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielPintoSouza committed Dec 30, 2024
1 parent d474123 commit 782080f
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions html/funcionario/dependente_listar_um.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
<?php

session_start();
if (!isset($_SESSION["usuario"])){
if (!isset($_SESSION["usuario"])) {
header("Location: ../../index.php");
}

// Verifica Permissão do Usuário
require_once '../permissao/permissao.php';
permissao($_SESSION['id_pessoa'], 11, 7);

$id_dependente = trim(filter_input(INPUT_POST, 'id_dependente', FILTER_SANITIZE_NUMBER_INT));

require_once "../../dao/Conexao.php";
$pdo = Conexao::connect();
$id_dependente = $_POST["id_dependente"];
if (!$id_dependente || $id_dependente < 1) {
http_response_code(400);
echo json_encode(['erro' => 'O id de um dependente deve ser um inteiro positivo maior ou igual a 1.']);
exit();
}

try {
require_once "../../dao/Conexao.php";
$pdo = Conexao::connect();

$dependente = $pdo->query("SELECT *, par.descricao AS parentesco
FROM funcionario_dependentes fdep
LEFT JOIN pessoa p ON p.id_pessoa = fdep.id_pessoa
LEFT JOIN funcionario_dependente_parentesco par ON par.id_parentesco = fdep.id_parentesco
WHERE fdep.id_dependente = $id_dependente;");
$dependente = $dependente->fetchAll(PDO::FETCH_ASSOC)[0];
$dependente = json_encode($dependente);
$stmt = $pdo->prepare('SELECT *, par.descricao AS parentesco
FROM funcionario_dependentes fdep
LEFT JOIN pessoa p ON p.id_pessoa = fdep.id_pessoa
LEFT JOIN funcionario_dependente_parentesco par ON par.id_parentesco = fdep.id_parentesco
WHERE fdep.id_dependente = :idDependente');

echo $dependente;
$stmt->bindParam(':idDependente', $id_dependente);
$stmt->execute();

die();
$dependente = $stmt->fetch(PDO::FETCH_ASSOC);

echo json_encode($dependente);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['erro' => 'Erro no servidor ao listar dependente.']);
exit();
}

0 comments on commit 782080f

Please sign in to comment.