Laravel csrf-token mismatch - laravel

Problem. When I follow an simple authentication tutorial for Laravel (v.5.2), and tries to register a new user I get the error: CSRF-token mismatch.
I am quite new to Laravel, and I am not sure how to proceed.
Background. I crated a new project for the tutorial, and runs it on my local machine (windows 10, on port 8000). I run it with Composer and artisan. My database are also on my local machine with XAMPP (on port 10080).
Code. https://github.com/isak-glans/laravel_problem
The tutorial:
https://www.youtube.com/watch?v=k89EOb9fqa0&list=PL_UnIDIwT95PiPV641VBnEwFAvswNZKuX&index=11

You need to add a cross site request forgery field to your form
<input type="hidden" name="_token" value="{{ csrf_token() }}">
or use the helper method:
{{ csrf_field() }}
This is used to prevent CSRF attacks.
Sorry didn't check your code first.
I cloned the app and registered without problems. I think that you are getting that error because the token expired.
Checkout this thread:
https://laracasts.com/discuss/channels/laravel/csrf-token-mismatch-error-on-session-timeout-form/

Related

Sagepay direct upgrade 4.0 does not open 3d secure page in live mode

I am upgrading sagepay(opayo) direct from 2.23 to 4.0. After upgrade 3d secure page is not opening in live mode.
I have used sagepay direct mode. After giving the card details got the "Status=3DAUTH". Then i redirect to another page where 3d secure page will open in an iframe.
In Test mode checking:
After full implementation i have tested in test mode. In test mode "challan" page came up successfully and its successfully authenticated. And payment successful.
Test In live Mode:
When i test in live mode with soldo virtual card its successfully open the 3d secure page. After approve the payment from soldo app, payment is successfull. And its done.
Now when i try amex card it shown 3d secure page loading screen and then given below error.
Oops ! An error occurred!!!
Internal processing Error..!!!
Now i have tried to do payment in master card. In this case when i redirect to 3d secure page. No thing is showing in iframe. And its stuck.
I have sending below params when trying to 1st call
$strPost = $strPost . "&Apply3DSecure=0";
$strPost = $strPost . "&AccountType=E";
$strPost = $strPost . "&BrowserAcceptHeader=text/html,application/xhtml+xml,application/xml&BrowserColorDepth=24&BrowserJavaEnabled=1&BrowserJavascriptEnabled=1&BrowserLanguage=en-GB&BrowserScreenHeight=1080&BrowserScreenWidth=1920&BrowserTZ=%2B300&BrowserUserAgent=Mozilla&ChallengeWindowSize=01";
$strPost = $strPost . "&ThreeDSNotificationURL=".$strYourSiteFQDN."3DCalBack.php?pagename=transactionRegistration.php&VendorTxCode=".$strVendorTxCode;
$strPost = $strPost ."&COFUsage=FIRST&InitiatedType=CIT&MITType=UNSCHEDULED";
ACSURL submit form
<form name="form" action="{$ACSURL}?creq=".$strCReq" method="POST">
<input type="hidden" name="PaReq" value="{$strPAReq}"/>
<input type="hidden" name="creq" value="{$strCReq}"/>
<input type="hidden" name="TermUrl" value="{$TermUrl}?VendorTxCode={$strVendorTxCode}"/>
<input type="hidden" name="MD" value="{$strMD}"/>
<input type="hidden" name="VPSTxId" value="{$strVPSTxId}"/>
<input type="hidden" name="mode" value="secure3d"/>
</form>
Please help me get fixed 3d secure page.
First, make sure this is not a Frictionless Authentication. From the docs:
For a frictionless authentication, the 3D Secure scheme has enough
information about the cardholder to provide an instant authentication
result. When the authentication process has completed the transaction
is submitted for authorisation.
I.e there is need to ask for the code and redirect to the 3-D Secure page (or show it in iframe). If necessary, you may use the Apply3DSecure=1 param in your initial request to SagePay, so that 3-D Secure check is always forced.
Second, for the 3-D Secure v2 redirection the list of the form fields should be:
<form action="{$ACSURL}" method="post">
<input type="text" name="ACSTransID" value="{$strACSTransID}" />
<input type="text" name="creq" value="{$strCReq}" />
<input type="text" name="TermUrl" value="{$TermUrl}?VendorTxCode={$strVendorTxCode}" />
</form>
All data should be POST-ed, and you should include the ACSTransID value from the response to your initial request. Note: fields PaReq and MD are related to 3-D Secure v1. If for some reason you would like to keep the backwards compatibility your current integration should be fine. In such case you may check the response for the initial request:
if it contains CReq and ACSTransID fields, then SagePay expects the communication via v2 protocol
if there are PaReq and MD fields, it's v1 protocol
However, 3-D Secure v1 is going to be withdrawn soon on October, 15 2022. So apparently keeping the backwards compatibility is not necessary.

CSRF token is not set when first accessing Laravel Application on shared hosting (419 Page Expired)

I deployed my laravel application in a shared hosting system and the application works fine, but every time I open the website for the first time in a new browser the first POST request that I make returns error 419, page expired. After that the system works fine, every POST is made correctly but I don't know why always this error happens the first time the system is opened in a new browser. The csrf_token is correct at the code.
<form method="POST">
#csrf
<input class="fields" name="user" placeholder="Email"/><br/>
<input class="fields" name="password" type="password" placeholder="Senha"/><br/>
<input class="entrarbtn" value="Entrar" type="submit"/><br/>
</form>
just added this settings on php.ini and works now
; cPanel-generated php ini directives, do not edit
; Manual editing of this file may result in unexpected behavior.
; To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
; For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
output_buffering = 16384

Laravel Valet not working with Laravel

I have been trying to use Valet but I found a problem. I created a new Laravel 5.2 project but I can't access the public assets files.
The only information I can tell is this error:
<br />
<b>Notice</b>: Undefined index: extension in <b>/Users/tiagocardoso/.composer/vendor/laravel/valet/cli/drivers/ValetDriver.php</b> on line <b>121</b><br />
Chrome Console Information:
http://ads.dev/css/app.css net::ERR_BLOCKED_BY_CLIENT
Ad Block blocks anything that includes ads in the filename. My thinking is ads.dev is causing everything. Do you have that enabled?
BLOCKED_BY_CLIENT means your browser is blocking them from loading.

Trac Error. Missing or invalid form token. Do you have cookies enabled?

I'm developing a plugin for Trac and trying to submit some info to the database
The scheme is:
Check a user you want to add to a department
Click a button to issue an ajax POST request
Process Request.
Everything was pretty fine while I was working with old 0.11 release. (not sure if that's the reason.
The company I've been working at updated Trac to the current stable 1.0.1 release and something is really wrong now.
Sending POST request without any data like this:
$.post("trac_dep_policy");
Went fine, but if I try to add some data:
$.post("trac_dep_policy", { name: "John", time: "2pm" } );
I get 400 Bad Request error.
After some debugging I figured out it's the protection against CSRF attacks that is working against me. (web/main.py)
The question is simple - how should I deal with it?
CSRF protection is auto-added to each form by a combination of in-place Genshi template modification and read-back on POST request, and I know this has been added very early, fixed version in Trac 0.10.2 release to be clear.
You'll need to use XMLRPC protocol (see XMLRPC plugin) or read the hidden form token yourself.
The answer was simple enough:
Just as #hasienda mentioned in his answer - each form in Trac is provided with a hidden input inside a div element with a certain name tag and a token value:
<form>
<div>
<input type="hidden" name="__FORM_TOKEN" value="9c69c37f52f669fb99b095e4">
</div>
</form>
Now, everything you'll need to do a successful POST request via ajax is to pass this __FORM_TOKEN value together with your data:
var token_value = $("input[name=__FORM_TOKEN]").val();
$.post(url, {__FORM_TOKEN: token_value, data: your_data})

How to change simple form post into an AJAX calls

I have a really simple webform;
<form name="logmeinsupport" action="https://secure.logmeinrescue.com/Customer/Code.aspx" method="post">
<span>Enter your 6-digit PIN code: </span><input type="text" name="Code" /><br />
<input type="submit" value="Connect to technician" />
</form>
On the logmeinrescue side, there will post the error code back into URL:
Like: http://tomtom-uk--tst2.tomtom.com/app/utils/support_login?LogMeInRescueResponse=PINCODE_INVALID
However, our server setup interprets it as a page in web server, therefore, i got 404 error:
404 Page Not Found
The page 'utils/support_login?LogMeInRescueResponse=PINCODE_INVALID.php' was not found.
It is not so easy for our infrastructure team to change it. I am wondering whether I can use Ajax call backs post function to get response. And i think the difficult is about cross server ajax call.
Any examples? Thanks
Cheers,
Qing
The server looks for the file 'utils/support_login?LogMeInRescueResponse=PINCODE_INVALID.php'.
I think you should change your request to:
utils/support_login.php?LogMeInRescueResponse=PINCODE_INVALID
In this way the server will look for support_login.php and if there is indeed a file with this name on your server you will not have this error again.

Resources