From 0f7eddd6a048b97028a468f1ba96a29aa62b0404 Mon Sep 17 00:00:00 2001 From: Krzysztof Turek Date: Sun, 15 Nov 2026 23:44:46 +0100 Subject: [PATCH] =?UTF-8?q?Poprawki=20bezpiecze=C5=84stwa=20formularza=20i?= =?UTF-8?q?=20panelu=20ustawie=C5=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - wp_unslash dla pól formularza i opcji (koniec z \' w mailach) - panel: wymagany nonce i manage_options, sanityzacja, esc_attr - reCAPTCHA: oczekiwana akcja i próg wyniku 0.5 - From z domeny strony, adres nadawcy tylko w Reply-To - honeypot bez die(), walidacja JS nie jest omijana - komunikat o nieudanej wysyłce, zachowanie wpisanych pól - nowy wygląd formularza (klasy ic-*) i szablon maila Co-Authored-By: Claude Fable 5.2 --- css/inContact.css | 211 +++++++++++++- inc/classes/inContact/AdminMenu.php | 106 +++---- inc/classes/inContact/Enqueue.php | 34 ++- inc/classes/inContact/Shortcode.php | 415 ++++++++++++++++------------ languages/in-contact-pl_PL.mo | Bin 2324 -> 2454 bytes languages/in-contact-pl_PL.po | 4 + languages/in-contact.pot | 4 + 7 files changed, 506 insertions(+), 268 deletions(-) diff --git a/css/inContact.css b/css/inContact.css index be6ab84..a6ba9f1 100644 --- a/css/inContact.css +++ b/css/inContact.css @@ -1 +1,210 @@ -form #website{ display:none; } \ No newline at end of file +/* ============================================================ + inContact — cform.css v0.3 + Dark, modern, photography-focused form styles + Prefix: .ic- (inContact) + ============================================================ */ + +/* ---------- Tokeny ---------- */ +:root { + --ic-bg: #ffffff; + --ic-surface: #f8f8f8; + --ic-border: #dde0e8; + --ic-border-focus: #2563eb; + --ic-text: #1a1d26; + --ic-text-muted: #8a909e; + --ic-accent: #2563eb; + --ic-accent-dark: #1a4fc4; + --ic-error: #dc2626; + --ic-success-bg: #f0fdf4; + --ic-success-txt: #166534; + --ic-error-bg: #fef2f2; + --ic-radius: 6px; + --ic-transition: 200ms ease; + --ic-font: inherit; +} + +/* ---------- Wrapper ---------- */ +.ic-wrap { + max-width: 680px; + margin: 0 auto; + padding: 40px 48px; + background: var(--ic-surface); + border: 1px solid var(--ic-border); + border-radius: 10px; + box-shadow: 0 4px 24px rgba(0, 0, 0, 0.07); +} + +/* ---------- Alerty ---------- */ +.ic-alert { + padding: 14px 18px; + border-radius: var(--ic-radius); + margin-bottom: 28px; + font-size: 0.92rem; + line-height: 1.5; +} + +.ic-alert--success { + background: var(--ic-success-bg); + color: var(--ic-success-txt); + border: 1px solid #1e5e38; +} + +.ic-alert--error { + background: var(--ic-error-bg); + color: var(--ic-error); + border: 1px solid #5e1e1e; +} + +/* ---------- Pola formularza ---------- */ +.ic-field { + margin-bottom: 22px; + position: relative; +} + +/* Honeypot — ukryte */ +.ic-field--honey { + position: absolute; + left: -9999px; + width: 1px; + height: 1px; + overflow: hidden; + opacity: 0; +} + +.ic-field label { + display: block; + margin-bottom: 7px; + font-size: 0.82rem; + font-weight: 600; + letter-spacing: 0.08em; + text-transform: uppercase; + color: var(--ic-text-muted); +} + +.ic-field input[type="text"], +.ic-field input[type="email"], +.ic-field textarea { + display: block; + width: 100%; + padding: 12px 16px; + background: var(--ic-bg); + border: 1px solid var(--ic-border); + border-radius: var(--ic-radius); + color: var(--ic-text); + font-size: 1rem; + font-family: inherit; + line-height: 1.5; + transition: + border-color var(--ic-transition), + box-shadow var(--ic-transition); + box-sizing: border-box; + -webkit-appearance: none; + appearance: none; +} + +.ic-field input::placeholder, +.ic-field textarea::placeholder { + color: var(--ic-text-muted); + opacity: 1; +} + +.ic-field input:focus, +.ic-field textarea:focus { + outline: none; + border-color: var(--ic-border-focus); + box-shadow: 0 0 0 3px rgba(226, 176, 74, 0.15); +} + +.ic-field textarea { + resize: vertical; + min-height: 130px; +} + +/* ---------- Walidacja ---------- */ +.ic-field__error { + display: none; + margin-top: 6px; + font-size: 0.8rem; + color: var(--ic-error); +} + +.ic-field--invalid input, +.ic-field--invalid textarea { + border-color: var(--ic-error); + box-shadow: 0 0 0 3px rgba(224, 85, 85, 0.15); +} + +.ic-field--invalid .ic-field__error { + display: block; +} + +/* ---------- reCAPTCHA ---------- */ +.ic-field--captcha { + margin-bottom: 26px; +} + +/* reCAPTCHA ma własny iframe — filtrujemy tak żeby ciemne tło nie świeciło przez padding */ +.ic-field--captcha .g-recaptcha { + display: inline-block; + border-radius: var(--ic-radius); + overflow: hidden; +} + +/* ---------- Przycisk ---------- */ +.ic-field--submit { + margin-top: 8px; + margin-bottom: 0; +} + +#ic-submit { + display: inline-flex; + align-items: center; + gap: 8px; + padding: 13px 32px; + background: var(--ic-accent); + color: #ffffff; + border: none; + border-radius: var(--ic-radius); + font-size: 0.95rem; + font-weight: 700; + letter-spacing: 0.04em; + cursor: pointer; + transition: + background var(--ic-transition), + transform var(--ic-transition), + box-shadow var(--ic-transition); + -webkit-appearance: none; + appearance: none; +} + +#ic-submit svg { + flex-shrink: 0; + transition: transform var(--ic-transition); +} + +#ic-submit:hover { + background: var(--ic-accent-dark); + box-shadow: 0 4px 20px rgba(37, 99, 235, 0.3); + transform: translateY(-1px); +} + +#ic-submit:hover svg { + transform: translateX(2px) translateY(-2px); +} + +#ic-submit:active { + transform: translateY(0); + box-shadow: none; +} + +#ic-submit:focus-visible { + outline: 2px solid var(--ic-accent); + outline-offset: 3px; +} + +/* ---------- Responsywność ---------- */ +@media (max-width: 640px) { + .ic-wrap { + padding: 28px 20px; + } +} diff --git a/inc/classes/inContact/AdminMenu.php b/inc/classes/inContact/AdminMenu.php index 1b0b896..c166079 100644 --- a/inc/classes/inContact/AdminMenu.php +++ b/inc/classes/inContact/AdminMenu.php @@ -39,49 +39,35 @@ class AdminMenu public function InContactSettings() { - $updated = isset($_POST["updated"]) ? $_POST["updated"] : ""; - $incontactconfig = isset($_REQUEST["incontact-config"]) - ? $_REQUEST["incontact-config"] + $nonce = isset($_POST["incontact-config"]) + ? sanitize_text_field(wp_unslash($_POST["incontact-config"])) : ""; if ( - $updated === "true" || - wp_verify_nonce($incontactconfig, "incontact-update") + $_SERVER["REQUEST_METHOD"] === "POST" && + current_user_can("manage_options") && + wp_verify_nonce($nonce, "incontact-update") ) { - - update_option("incontact-site-key", $_POST["incontact-site-key"]); - update_option( - "incontact-secret-key", - $_POST["incontact-secret-key"], - ); - update_option( - "incontact-target-mail", - $_POST["incontact-target-mail"], - ); - update_option( - "incontact-form-ph-name", - $_POST["incontact-form-ph-name"], - ); - update_option( - "incontact-form-ph-email", - $_POST["incontact-form-ph-email"], - ); - update_option( - "incontact-form-ph-message", - $_POST["incontact-form-ph-message"], - ); - update_option("incontact-form-name", $_POST["incontact-form-name"]); - update_option( - "incontact-form-email", - $_POST["incontact-form-email"], - ); - update_option( - "incontact-form-message", - $_POST["incontact-form-message"], - ); - update_option( - "incontact-form-snd-ok", - $_POST["incontact-form-snd-ok"], - ); + $fields = [ + "incontact-site-key" => "sanitize_text_field", + "incontact-secret-key" => "sanitize_text_field", + "incontact-target-mail" => "sanitize_email", + "incontact-form-ph-name" => "sanitize_text_field", + "incontact-form-ph-email" => "sanitize_text_field", + "incontact-form-ph-message" => "sanitize_text_field", + "incontact-form-name" => "sanitize_text_field", + "incontact-form-email" => "sanitize_text_field", + "incontact-form-message" => "sanitize_text_field", + "incontact-form-snd-ok" => "sanitize_text_field", + ]; + foreach ($fields as $option => $sanitize) { + if (!isset($_POST[$option])) { + continue; + } + update_option( + $option, + $sanitize(wp_unslash($_POST[$option])), + ); + } ?>
@@ -108,9 +94,7 @@ class AdminMenu "in-contact", ); ?> " class="regular-text"/> + value="" class="regular-text"/> " class="regular-text"/> + value="" class="regular-text"/> " class="regular-text"/> + value="" class="regular-text"/> @@ -139,9 +119,7 @@ class AdminMenu "in-contact", ); ?> " class="regular-text"/> + value="" class="regular-text"/> " class="regular-text"/> + value="" class="regular-text"/> " class="regular-text"/> + value="" class="regular-text"/> @@ -170,9 +144,7 @@ class AdminMenu "in-contact", ); ?> " class="regular-text"/> + value="" class="regular-text"/> " class="regular-text"/> + value="" class="regular-text"/> " class="regular-text"/> + value="" class="regular-text"/> @@ -201,9 +169,7 @@ class AdminMenu "in-contact", ); ?> " class="regular-text"/> + value="" class="regular-text"/> diff --git a/inc/classes/inContact/Enqueue.php b/inc/classes/inContact/Enqueue.php index 39e7bf8..3a3ca86 100644 --- a/inc/classes/inContact/Enqueue.php +++ b/inc/classes/inContact/Enqueue.php @@ -11,19 +11,25 @@ namespace inContact; * @version 0.2 */ - class Enqueue { +class Enqueue +{ + use Singleton; - use Singleton; - - function __construct() { + /*function __construct() { add_action('wp_enqueue_scripts',[ $this, 'enqueueScripts']); - } - - public function enqueueScripts() { - global $pluginDirUrl, $pluginPath; - wp_register_style('ContactCss', $pluginDirUrl.'css/inContact.css', [], filemtime( $pluginPath . 'css/inContact.css'), 'all'); - - wp_enqueue_style('ContactCss'); - - } - } \ No newline at end of file + }*/ + + public function enqueueScripts() + { + global $pluginDirUrl, $pluginPath; + wp_register_style( + "ContactCss", + $pluginDirUrl . "css/inContact.css", + [], + filemtime($pluginPath . "css/inContact.css"), + "all", + ); + + wp_enqueue_style("ContactCss"); + } +} diff --git a/inc/classes/inContact/Shortcode.php b/inc/classes/inContact/Shortcode.php index d2c5378..aa22552 100644 --- a/inc/classes/inContact/Shortcode.php +++ b/inc/classes/inContact/Shortcode.php @@ -3,12 +3,12 @@ namespace inContact; /** - * Klasa Menus + * Klasa Shortcode * * @link https://krzysztof-turek.com * * @package tylkofotografia.pl - * @version 0.2 + * @version 0.3 */ class Shortcode { @@ -29,29 +29,34 @@ class Shortcode $em_name = null; $em_mail = null; $em_message = null; - $class = null; $html = null; $error = null; $body = null; $telefon = null; $mailResult = 0; + $canSend = false; + $sendFailed = false; + $form_submitted = $_SERVER["REQUEST_METHOD"] === "POST"; - if (!empty($_POST["website"])) { - die(); - } + global $pluginDirUrl; + + // Honeypot — bot dostaje pozorny sukces, mail nie jest wysyłany + $isBot = !empty($_POST["website"]); + if ($form_submitted) { $emmsg = isset($_POST["emmsg"]) ? $_POST["emmsg"] : ""; + // Walidacja pól if (!empty($_POST["em_name"])) { - $em_name = $_POST["em_name"]; + $em_name = sanitize_text_field(wp_unslash($_POST["em_name"])); } else { $error .= esc_html__("Please enter your name", "in-contact") . "
"; } - if (!empty($_POST["em_mail"])) { - $em_mail = $_POST["em_mail"]; + if (!empty($_POST["em_mail"]) && is_email($_POST["em_mail"])) { + $em_mail = sanitize_email(wp_unslash($_POST["em_mail"])); } else { $error .= esc_html__( @@ -60,41 +65,47 @@ class Shortcode ) . "
"; } if (!empty($_POST["em_message"])) { - $em_message = $_POST["em_message"]; + $em_message = sanitize_textarea_field( + wp_unslash($_POST["em_message"]), + ); } else { $error .= esc_html__("Please enter your message", "in-contact") . "
"; } - $targetEmail = - "To: Tylkofotografia <" . - get_option("incontact-target-mail") . - ">"; - $mailResult = 0; - $headers = "MIME-Version: 1.0" . "\r\n"; - $headers .= - "Content-type: text/html; charset=" . - get_bloginfo("charset") . - "" . - "\r\n"; - $headers .= "From: " . $em_name . " <" . $em_mail . ">" . "\r\n"; + // Budowanie emaila + // From z domeny strony (SPF/DMARC), adres nadawcy tylko w Reply-To + $siteHost = (string) wp_parse_url(home_url(), PHP_URL_HOST); + if (strpos($siteHost, "www.") === 0) { + $siteHost = substr($siteHost, 4); + } + $headerChars = ["\"", "<", ">", "\r", "\n"]; + $fromName = str_replace( + $headerChars, + "", + wp_specialchars_decode(get_bloginfo("name"), ENT_QUOTES), + ); + $replyName = str_replace($headerChars, "", (string) $em_name); $headers = [ "Content-Type: text/html; charset=UTF-8", - "From: " . $em_name . " <" . $em_mail . ">", - "Reply-To: " . $em_name . " <" . $em_mail . ">", + "From: " . $fromName . " ", + "Reply-To: " . $replyName . " <" . $em_mail . ">", ]; + + $targetEmail = get_option("incontact-target-mail"); $emailTitle = __("New message from contact form", "in-contact"); $emailHeading = __("Contact details", "in-contact"); $emailNameLabel = __("Name and surname", "in-contact"); $emailEmailLabel = __("Email", "in-contact"); - $emailMessageHeading = __("Message content", "in-contact"); + $emailMsgHeading = __("Message content", "in-contact"); $emailReplyLabel = __("Reply to message", "in-contact"); $emailFooter = __( "This email was generated automatically by the website contact form.", "in-contact", ); $emailRights = __("All rights reserved.", "in-contact"); + $body = ' @@ -104,70 +115,24 @@ class Shortcode esc_html($emailTitle) . '
-
-

' . +

' . esc_html($emailTitle) . - '

-
+ '

' . esc_html($emailHeading) . @@ -178,15 +143,12 @@ class Shortcode

' . esc_html($emailEmailLabel) . ': {{EMAIL}}

- -

' . - esc_html($emailMessageHeading) . - ':

+ esc_html($emailMsgHeading) . + '

{{WIADOMOSC}}

- ' . esc_html($emailReplyLabel) . ' @@ -195,14 +157,16 @@ class Shortcode ' . esc_html($emailFooter) . '
- © {{ROK}} Twoja Firma. ' . + © {{ROK}} ' . + esc_html(get_bloginfo("name")) . + ". " . esc_html($emailRights) . '
- -'; +'; + $body = str_replace( [ "{{IMIE_NAZWISKO}}", @@ -212,35 +176,44 @@ class Shortcode "{{ROK}}", ], [ - $em_name, - $em_mail, - $telefon, - str_replace(["\r\n", "\r", "\n"], "
", $em_message), + esc_html($em_name), + esc_html($em_mail), + esc_html($telefon), + str_replace( + ["\r\n", "\r", "\n"], + "
", + esc_html($em_message), + ), date("Y"), ], $body, ); - $gRecaptchaResponse = isset($_POST["g-recaptcha-response"]) - ? $_POST["g-recaptcha-response"] - : ""; + // Obsługa błędów walidacji if (!empty($error)) { $html .= - '