Vigyata.AI
Is this your channel?

A Huge Security Risk To Your Website - Cross-Site Scripting (XSS) - Practical Example and Solutions

9.3K views· 385 likes· 18:33· Jan 9, 2023

🛍️ Products Mentioned (10)

Here, we will be looking at a huge security risk that Cross-Site Scripting (XSS) can cause to your website. We will be looking at what a hacker can do and how to solve it using 3 ways. Know more about Cross-Site Scripting: https://developer.mozilla.org/en-US/docs/Glossary/Cross-site_scripting === OFFER === GET 30% DISCOUNT ON ALL PLANS OF CLOUDWAYS HOSTING FOR 3 MONTHS https://unified.cloudways.com/signup?id=1029148&coupon=CW30FOR3 === Important Links === Fonts, extensions I use, and Support Laratips links: https://bit.ly/m/laratips === Video Related Links === JS Minifier: https://www.toptal.com/developers/javascript-minifier HTML purify package: https://github.com/stevebauman/purify Content Security Policy (CSP): https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/default-src https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources 00:00 Intro 01:22 The mistake 02:10 The basic exploitation 03:27 Solution 1 04:12 The bigger exploitation 08:18 Solution 2 11:59 Solution 3 18:14 Thank you === Other Videos === What's New In Laravel 9 https://youtu.be/qAzrZUG_9Z0 New In Laravel Playlist https://www.youtube.com/playlist?list=PL2DahmvUpeuu4UVWrcxlvVkMiI0SeS2OZ Laravel Package Development Playlist https://www.youtube.com/playlist?list=PL2DahmvUpeuu8HkpbNT-cKernolVdqZq_ Password Validation In Laravel with at least one Letters, Numbers, Upper and Lowercase or Symbols: https://youtu.be/f-g3P9imPZs Multiple Apis With ForwardsCalls Trait And Code Refactoring Tip - Laravel Hidden Feature: https://youtu.be/vzgNm86ezWE Laravel Chunking - You Might Be Doing This Wrong - Problem and Solution: https://youtu.be/aQCHmB4Uh0Q Laravel Tip - Properly Get Data Between Two Dates https://youtu.be/bJkEBTg1NGA Get Data From Multiple Databases In One Project | Laravel Tip https://youtu.be/KJAXLf78QPs === Attribution === Boy waving hand Video by VideoPlasty .com (https://pixabay.com/users/videoplasty-19751245/?utm_source=link-attribution&utm_medium=referral&utm_campaign=video&utm_content=80696) from Pixabay Thumbnail Photo by Tima Miroshnichenko: https://www.pexels.com/photo/person-in-black-hoodie-sitting-on-chair-5380621 #laravel #php #laraveltip #laratips

About This Video

In this video I’m showing you a huge security risk that can be sitting inside your Laravel app without you even realizing it: Cross-Site Scripting (XSS). I walk through a very practical example using a simple dashboard where users can create posts, and I point out the blunder mistake I also did in my earlier days—rendering user input with raw output so whatever is inside a <script> tag just runs. First I demonstrate a basic exploit with an alert, and then I show a bigger exploitation where a malicious user injects JavaScript that keeps sending requests and fills your database with junk posts, and you only find out after an innocent user complains. After that, I go through three solutions. Solution 1 is the obvious one: don’t render raw HTML—use escaped output so scripts don’t execute. But if you’re allowing rich text (bold, italics, paragraphs), then you need a better approach. Solution 2 is HTML sanitization using the stevebauman/purify package, either by cleaning on output or by using model casting so you don’t have to remember it everywhere. Solution 3 is adding a Content Security Policy (CSP) header via middleware to block inline script execution and control which script sources are allowed—this is a very strong extra layer of defense.

Frequently Asked Questions

🎬 More from Laratips