Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion source/_partials/contact_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function loadImage(token) {

if (this.readyState == 4) {
if (this.status == 200) {
window.top.location.href = 'thank-you-contact'
window.top.location.href = '{{ locale_url($page, 'thank-you-contact') }}'
} else {
let message = document.getElementById('message')
message.textContent = '{{ $page->t( 'Invalid Captcha') }}'
Expand Down
1 change: 1 addition & 0 deletions suitecrm-form-middleware/audio_captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Gregwar\Captcha\CaptchaBuilder;
use Libresign\Espeak\Espeak;

\App\Support\Http\SessionCookie::configureCrossSite();
session_start();

header("Access-Control-Allow-Origin: {$_ENV['URL_SITE']}");
Expand Down
1 change: 1 addition & 0 deletions suitecrm-form-middleware/captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$builder = new CaptchaBuilder();
$builder->build();

\App\Support\Http\SessionCookie::configureCrossSite();
session_start();

header("Access-Control-Allow-Origin: {$_ENV['URL_SITE']}");
Expand Down
7 changes: 6 additions & 1 deletion suitecrm-form-middleware/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

include "../vendor/autoload.php";
use Gregwar\Captcha\CaptchaBuilder;
\App\Support\Http\SessionCookie::configureCrossSite();
session_start();

header("Access-Control-Allow-Origin: {$_ENV['URL_SITE']}");
header("Access-Control-Allow-Credentials: true");

$builder = new CaptchaBuilder($_SESSION['code']);
$builder = new CaptchaBuilder($_SESSION['code'] ?? null);
$codeImg = filter_input(INPUT_POST, 'codeImg');

session_write_close();

if( !$builder->testPhrase($codeImg)){
http_response_code(404);
return;
Expand All @@ -29,6 +32,8 @@
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $formulario_data);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);

$resposta = curl_exec($ch);

Expand Down
22 changes: 22 additions & 0 deletions support/Http/SessionCookie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Support\Http;

class SessionCookie
{
public static function configureCrossSite(): void
{
$isHttps = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off')
|| (($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https');

session_set_cookie_params([
'lifetime' => 0,
'path' => '/',
'secure' => $isHttps,
'httponly' => true,
'samesite' => $isHttps ? 'None' : 'Lax',
]);
}
}
Loading