The Foundations

What is Client-Side Hacking?

Architecture Overview
🗃 Database
Web Server
HTTP Request / Response
🌐 Browser (Client)

JavaScript

JavaScript Properties
Object-Oriented Platform Independent Update HTML via DOM Exception Handling Anonymous Functions Make Web Pages Alive

Variables, Functions, Conditionals, and Objects

JavaScript
// variable assignment
myVariable = 2;

// function definition
function myFunc(val) {
    console.log("Input val is: ", val);
    // log if val is positive or negative
    if (val >= 0) {
        console.log("input val is positive");
    }
    else {
        console.log("input val is negative");
    }
    return val+1;
}

// calling function
result = myFunc(myVariable)
console.log("result: ",result);

// object definition
myObject = {"key1":"value1","key2":1,"key3":{"hello":"world"}};
// access properties with [] or . notation
console.log("key1 is: ", myObject['key1']);
console.log("key3.hello is: ", myObject.key3["hello"]);
Output Input val is: 2 input val is positive result: 3 key1 is: value1 key3.hello is: world

The DOM

DOM Tree Structure
Document
└─ html
└─ head
└─ title
└─ body
└─ div
└─ p h1
└─ ul
└─ li li li

Safe vs Dangerous DOM Manipulation

Safe — Won't Cause XSS
// These will not cause XSS
document.body.innerText =
  "<img/src/onerror=alert()>";

document.body.textContent =
  "<img/src/onerror=alert()>";
Dangerous — Can Lead to XSS
// These can lead to XSS
document.body.innerHTML =
  "<img/src/onerror=alert('XSS!')>";

document.write(
  "<img/src/onerror=alert('XSS!')>");
⚠ This page says:
XSS!
Next: Sources & Sinks