ThishVerse Logo
THISHVERSE
HomeBlogAboutContact
Back to all posts
Cybersecurity

Website එකකට Malicious Script එකක් ඇතුළු වුණොත්?

XSS attacks කියන්නේ මොනවාද, ඒවා ක්‍රියා කරන්නේ කොහොමද, සහ websites ඒවායින් ආරක්ෂා කරගන්නේ කොහොමද?

HHirun Thishakya
August 24, 2026
6 min read
Website එකකට Malicious Script එකක් ඇතුළු වුණොත්?

XSS කියන්නේ මොකක්ද?

XSS (Cross-Site Scripting) කියන්නේ attacker කෙනෙක්ට malicious HTML හෝ JavaScript code එකක් website එකකට ඇතුළත් කරලා, ඒක වෙනත් user කෙනෙකුගේ browser එක තුළ execute කරවීමට හැකිවන web security vulnerability එකක්.

සරලව කිව්වොත්

Website එකට සාමාන්‍ය data එකක් ලෙස ලැබිය යුතු input එකක්, browser එක විසින් code එකක් ලෙස execute වීමට ඉඩ දීම තමයි XSS වල මූලික ගැටලුව.

මෙහි වැදගත්ම දෙයක් තමයි attack එක බොහෝවිට සිදුවන්නේ victimගේ browser එක තුළ වීම.


සරල උදාහරණයක් බලමු

අපි comment section එකක් තියෙන website එකක් හිතමු.

User කෙනෙක් මෙහෙම comment එකක් දානවා:

I really enjoyed this article!

Website එකේ code එක user input එක safe විදිහට handle කරනවා නම් ඒක සාමාන්‍ය text එකක් ලෙස පෙන්වයි.

නමුත් attacker කෙනෙක් මේ වගේ HTML/JavaScript එකක් input කළා කියලා හිතන්න:

<script>
    alert ("This is an XSS attack!");
</script>

Website එක මේ input එක නිවැරදිව handle නොකළොත්, browser එකට මේක සාමාන්‍ය text එකක් විදිහට නැතුව executable JavaScript code එකක් විදිහට පෙනෙන්න පුළුවන්.

ඒ නිසා browser එක JavaScript එක execute කරලා popup එකක් පෙන්වන්න පුළුවන්.

මේ වගේ alert () එකක් සාමාන්‍යයෙන් හානිකර දෙයක් නොවුණත්, Attackerගේ code එක victimගේ browser එක තුළ execute වුනු ඒකෙන් පෙන්නන්නෙ වැදගත් security problem එකක්.


XSS භයානක ඇයි?

Attacker කෙනෙක් popup එකක් පෙන්වීමෙන් නතර වෙන්නේ නැහැ.

Vulnerability එකේ ස්වභාවය සහ website එකේ security controls අනුව XSS භාවිතා කරලා attacker කෙනෙක්ට:

  • Webpage එකේ පෙන්වන content වෙනස් කරන්න

  • User කෙනෙක් වෙනත් malicious website එකකට redirect කරන්න

  • Victimගේ authenticated session එක භාවිතා කර actions perform කරන්න

  • Page scripts වලට access කළ හැකි sensitive information ලබාගැනීමට උත්සාහ කරන්න

  • Website එකේ forms හෝ interface වෙනස් කරන්න

  • User කෙනෙක්ව fake interface එකකිිින් රවට්ටන්න

වගේ දේවල් කරන්න අවස්ථාව ලැබෙනවා.

ඒ නිසා XSS එකක් කියන්නේ popup එකක් පෙන්වන bug එකක් විතරක්ම නෙවෙයි.


XSS වල ප්‍රධාන වර්ග 3

XSS සාමාන්‍යයෙන් ප්‍රධාන වර්ග තුනකට බෙදනවා:

  1. Stored XSS

  2. Reflected XSS

  3. DOM-Based XSS

මේ තුනේ වෙනස තේරුම් ගන්න ලේසිම ක්‍රමය තමයි malicious input එක කොහේද තියෙන්නෙ සහ browser එකට කොහොමද යන්නේ කියලා බලන එක.


1. Stored XSS

Stored XSS වලදී attacker විසින් ඇතුළත් කරන malicious input එක application එකේ database එකක හෝ වෙනත් storage එකක save වෙනවා.

උදාහරණයක් ලෙස comment system එකක් ගනිමු.

Attacker submits comment
        ↓
Website saves the comment
        ↓
Another user opens the page
        ↓
Website displays the comment
        ↓
Malicious code executes

ඒ කියන්නේ attackerට malicious input එක එක වතාවක් ඇතුළත් කරලා, ඒ content එක බලන වෙනත් users ලාටත් attack කරන්න පුලුවන්.

ඒ නිසා Stored XSS විශේෂයෙන් භයානකයි.

Stored XSS ඇතිවිය හැකි ස්ථාන

  • Comment sections

  • Forums

  • Reviews

  • User profiles

  • Messaging systems


2. Reflected XSS

Reflected XSS වලදී malicious input එක website එකේ permanently save වෙන්නේ නැහැ.

ඒ වෙනුවට user request එකකින් server එකට යන input එක server response එක ඇතුලෙන් ආයෙත් reflect වෙනවා.

උදාහරණයක් විදිහට search page එකක් හිතන්න.

සාමාන්‍යයෙන්:

Search results for: laptop

වගේ message එකක් පෙන්වනවා.

Search input එක ආරක්ෂිතව handle නොකරන website එකකදී attacker කෙනෙක්ට malicious input එකක් request එක තුළ යවන්න පුළුවන්.

සාමාන්‍ය flow එක මෙහෙමයි:

Attacker creates malicious input
        ↓
Victim opens manipulated request
        ↓
Server reflects the input
        ↓
Browser receives the page
        ↓
Malicious code executes

මෙතනදි malicious content එක database එකක permanently store වෙන්න අවශ්‍ය නැහැ.


3. DOM-Based XSS

මේක ටිකක් වෙනස්.

DOM-Based XSS ඇතිවන්නේ server එකේ code එක නිසාම වෙන්න අවශ්‍ය නැහැ. Browser එකේ run වෙන client-side JavaScript code එක user-controlled data එක unsafe විදිහට handle කිරීමෙන් vulnerability එක ඇතිවෙන්න පුළුවන්.

DOM (Document Object Model) කියන්නේ browser එක webpage එක represent කරන ආකාරය.

Frontend developer කෙනෙක් URL එකකින් හෝ වෙනත් user-controlled source එකකින් data අරගෙන ඒක unsafe විදිහට webpage එකට insert කළොත්, DOM-based XSS ඇතිවිය හැක.

ඒ නිසා backend එක secure කිරීම විතරක් ප්‍රමාණවත් නැහැ.

Frontend JavaScript එකත් secure විදිහට ලියන්න ඕන.


XSS ඇතිවෙන්නේ ඇයි?

XSS වල මූලික ගැටලුවක් තමයි untrusted input එක විශ්වාස කිරීම.

Web application එකකට data එන්නේ විවිධ ස්ථානවලින්:

  • Text fields

  • Search boxes

  • Comments

  • URLs

  • Forms

  • User profiles

  • APIs

මේ data user කෙනෙක් control කරනවා නම්, ඒක safe කියලා assume කරන්න බැහැ.

ඒ නිසා web development වල වැදගත් security mindset එකක් තියෙනවා:

User-controlled data එක safe කියලා assume කරන්න එපා.


XSS වලින් ආරක්ෂා වෙන්නේ කොහොමද?

XSS prevent කරන්න එකම solution එකක් කියලා නැහැ. සාමාන්‍යයෙන් security techniques කිහිපයක් එකට භාවිතා කරනවා.

1. Output Encoding

User input එක webpage එකක display කරද්දී, browser එකට ඒක HTML හෝ JavaScript code එකක් ලෙස interpret කරන්න බැරි විදිහට encode කළ යුතුයි.

උදාහරණයක් ලෙස:

<script> alert("Hi") </script>

කියන input එක execute නොකර, browser එකේ සාමාන්‍ය text එකක් ලෙස පෙන්විය යුතුයි.

Modern web frameworks බොහෝවිට normal rendering methods භාවිතා කරන විට automatic escaping ලබාදෙනවා.

2. Input Validation

Application එකට ලැබෙන input එක validate කිරීමත් වැදගත්.

උදාහරණයක් විදිහට phone number එකක් ඇතුළත් කළ යුතු field එකකට HTML code අවශ්‍ය නැහැ.

ඒ නිසා expected format එකට නොගැළපෙන input reject කරන්න පුළුවන්.

නමුත් input validation එක පමණක් XSS protection එකක් ලෙස භාවිතා කිරීම ප්‍රමාණවත් නැහැ.

3. HTML Sanitization

සමහර websites වල users ලාට HTML formatting භාවිතා කරන්න අවශ්‍ය වෙනවා.

උදාහරණයක්:

  • Blog editor

  • Rich-text editor

  • Forum formatting

ඒ වගේ අවස්ථාවක සියලුම HTML ඉවත් කරන්න බැහැ.

ඒ වෙනුවට HTML sanitizer එකක් භාවිතා කරලා dangerous HTML elements සහ attributes ඉවත් කරලා, අවශ්‍ය safe formatting පමණක් තියාගන්න පුළුවන්.

4. Safe DOM APIs භාවිතා කිරීම

Frontend JavaScript ලියන විටත් developers ලා සැලකිලිමත් වෙන්න ඕන.

උදාහරණයක් ලෙස untrusted content එක innerHTML හරහා directly webpage එකට insert කිරීම අවදානම් වෙන්න පුලුවන්.

සාමාන්‍ය text එකක් පෙන්වන්න අවශ්‍ය නම්:

element.textContent = userInput;

වගේ safe approach එකක් භාවිතා කරන්න.

මෙතනදි browser එක user input එක HTML code එකක් විදිහට නැතුව text එකක් විදිහට සලකනවා.

5. Content Security Policy

Content Security Policy (CSP) කියන්නේ browser එකට website එකේ scripts සහ අනෙකුත් resources execute/load කිරීමට අවසර දෙන rules define කළ හැකි security mechanism එකක්.

නිවැරදිව configure කළ CSP එකක් තිබීමෙන් සමහර XSS attacks වල බලපෑම අඩු කිරීමට හෝ ඒවා execute වීම වැළැක්වීමට පුලුවන්.

නමුත් CSP එක වෙනත් XSS protections වෙනුවට භාවිතා කළ යුතු දෙයක් නෙවෙයි.


XSS සහ SQL Injection අතර වෙනස

XSS සහ SQL Injection දෙකම untrusted input වැරදි විදිහට handle කිරීමෙන් ඇතිවිය හැකි security vulnerabilities.

නමුත් ඒවා target කරන්නේ වෙනස් ස්ථාන.

XSS

SQL Injection

සාමාන්‍යයෙන් user's browser එක target කරනවා

Database එක target කරනවා

HTML/JavaScript වැනි content inject කරනවා

SQL syntax inject කරනවා

Webpage rendering එකේ vulnerability එකක්

Database query එකේ vulnerability එකක්

Victimගේ browser එකට බලපානවා

Database operations/data වලට බලපානවා


XSS කියන්නේ <script> tag එකක් form එකකට දාන එක විතරක් නෙවෙයි.

මෙතන deeper concept එක තමයි:

Data සහ Code අතර වෙනස නිවැරදිව පවත්වාගැනීම.

User කෙනෙකුගේ comment එක data එකක්.

Search query එක data එකක්.

Username එක data එකක්.

ඒ data browser එකට executable HTML හෝ JavaScript ලෙස interpret කරන්න ඉඩ දුන්නොත් security vulnerability එකක් ඇතිවෙන්න පුලුවන්.

ඒ නිසා කලින් කිව්වා වගේම secure web development වල වැදගත්ම principles වලින් එකක්:

Never blindly trust user-controlled input.


XSS තේරුම් ගැනීම web security ඉගෙනගන්න කෙනෙකුට ඉතා වැදගත් foundation එකක්. විශේෂයෙන් frontend සහ backend development කරද්දි, user input එක application එකට ඇතුළු වන්නේ කොතැනින්ද, ඒක යන්නේ කොතැනටද, සහ browser එකේ interpret කරන්නේ කොහොමද කියන දේ ගැන හිතන්න පුරුදු වීම වැදගත්.

Tags:Application SecurityXSSJavaScriptCross-Site ScriptingWeb SecurityCybersecurityOWASPWeb Vulnerabilities

Did you find this article helpful?

Related Articles

View Post
Azure වලින් මොනවද කරන්න පුළුවන්?
Cloud Computing
October 7, 2026

Azure වලින් මොනවද කරන්න පුළුවන්?

Microsoft Azure කියන්නේ විවිධ විදිහෙ දේවල් ගොඩක් කරන්න පුලුවන් cloud platform එකක්.

View Post
මොනවද මේ Linux Shell වර්ග?
DevOpsFeatured
October 2, 2026

මොනවද මේ Linux Shell වර්ග?

Linux වල තියෙන Bash, Zsh, Fish, Dash වගේ Shells අතර වෙනස්කම්

View Post
Flutter සහ React Native
Programming
September 24, 2026

Flutter සහ React Native

Mobile App Development එකට හොද මොකක්ද?

ThishVerse Logo
THISHVERSE
|

© 2026 ThishVerse. All rights reserved.

PrivacyTerms
|By Thish
Comments (0)

Sign in to join the conversation

No comments yet. Be the first to comment!