Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions owasp-top10-2021-apps/a5/vinijr-blog/app/contact.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
<?php
libxml_disable_entity_loader(true);

$xmlfile = file_get_contents('php://input');

$dom = new DOMDocument();
$dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD);

$dom->loadXML($xmlfile, LIBXML_NOENT | LIBXML_DTDLOAD | LIBXML_NOERROR | LIBXML_NOWARNING);

$contact = simplexml_import_dom($dom);
$name = $contact->name;
$email = $contact->email;
$subject = $contact->subject;
$message = $contact->message;

echo "Thanks for the message, $name !";
?>
if (isset($contact->name) && isset($contact->email) && isset($contact->subject) && isset($contact->message)) {
$name = htmlspecialchars($contact->name, ENT_QUOTES, 'UTF-8');
$email = filter_var($contact->email, FILTER_VALIDATE_EMAIL);
$subject = htmlspecialchars($contact->subject, ENT_QUOTES, 'UTF-8');
$message = htmlspecialchars($contact->message, ENT_QUOTES, 'UTF-8');

if ($email !== false) {
echo "Thanks for the message, $name!";
} else {
echo "Invalid email address!";
}
} else {
echo "Invalid XML format!";
}