CSRF stands for Cross-Site Request Forgery.
CSRF Protection is a security feature in Laravel (and all modern web frameworks) that helps prevent unauthorized or malicious requests from being made on behalf of an authenticated user.
๐ Simple Explanation (Hindi + English)
๐ธ English:
CSRF is an attack where a user is tricked into submitting a request they didnโt intend to. Laravel protects you from this by using CSRF tokens in forms. Only if the token matches, the request is accepted.
๐ธ Hindi:
CSRF เคเค เคเคธเคพ เคนเคฎเคฒเคพ เคนเฅเคคเคพ เคนเฅ เคเคฟเคธเคฎเฅเค user เคเฅ เคงเฅเคเฅ เคธเฅ เคเฅเค เคเคธเคพ request เคญเฅเคเคจเฅ เคเฅ เคฒเคฟเค เคฎเคเคฌเฅเคฐ เคเคฟเคฏเคพ เคเคพเคคเคพ เคนเฅ เคเคฟเคธเฅ เคตเคน เคเฅเคฆ เคจเคนเฅเค เคเคฐเคจเคพ เคเคพเคนเคคเคพเฅค Laravel เคเคธเคธเฅ เคฌเคเคพเคต เคเฅ เคฒเคฟเค เคนเคฐ form เคฎเฅเค CSRF token เคฆเฅเคคเคพ เคนเฅ, เคเฅ เคนเคฐ session เคเฅ เคฒเคฟเค unique เคนเฅเคคเคพ เคนเฅเฅค เค เคเคฐ เคฏเคน token valid เคจเคนเฅเค เคนเฅ เคคเฅ Laravel เคเคธ request เคเฅ reject เคเคฐ เคฆเฅเคคเคพ เคนเฅเฅค
โ Real-World Example (Hindi + English):
โ Imagine:
You’re logged into your bank account. If someone sends you a fake form that transfers money from your account, without CSRF protection, it might actually go through.
But with CSRF protection:
- Laravel adds a hidden token in every form.
- When the form is submitted, Laravel checks the token.
- If it doesnโt match โ request is rejected.
โ Syntax in Laravel Blade:
bladeCopyEdit<form method="POST" action="/submit">
@csrf <!-- This adds the CSRF token automatically -->
<input type="text" name="name">
<button type="submit">Submit</button>
</form>