This work is produced by John Häggerud for the course Server-based Web Programming (1DV023) at Linnaeus University.
All content in this work excluding photographs, icons, picture of course literature and Linnaeus University logotype and symbol, is licensed under a
Creative Commons Attribution 4.0 International License.
If you change the content do not use the photographs, icons, picture of the course literature or Linnaeus University logotype and symbol in your new work!
At all times you must give credit to: ”Linnaeus university – Server-based Web Programming (1DV023)” with the link https://coursepress.lnu.se/kurs/serverbaserad-webbprogrammering/ and to the Creative Common-license above.
The application must always assume that all input is potentially malicious
Open Web Application Security Project
Image from: http://excess-xss.com/ Excess XSS by Jakob Kallin and Irene Lobo Valbuena is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
document.querySelector('a').href = userInput
// userInput = "javascript:alert('hacked')"
Content-Security-Policy: default-src 'self'; img-src *;
media-src media1.com media2.com; script-src cdn.script.example.com
https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP
https://github.com/helmetjs/helmet
by using GET requests for state changing operations.
<form action="/account" method="post">
<input type="hidden" name="_csrf" value="HvtsC1Ka-yq1Q2KPAu_Yh_H8F4vJEYfMIlBQ" />
</form>
const sessionOptions = {
name: 'name of keyboard cat', // Don't use default session cookie name.
secret: 'keyboard cat', // Change it!!!
resave: false, // Resave even if a request is not changing the session.
saveUninitialized: false, // Don't save a created but not modified session.
cookie: {
secure: true, // should be true to check that we´re using HTTPS
httpOnly: true, // dont allow client script messing with the cookie
maxAge: 3200, // will live for 1 day
sameSite: 'lax' // protect against POST csrf-attack(?)
}
}
"SELECT * FROM user WHERE username='" + request.getParameter("username") + "'";
// will show all accounts
"SELECT * FROM user WHERE username='' or 1=1--"
db.myCollection.find( { $where: function() {
return obj.credits - obj.debits < $userInput; }
});
npm audit
npm install
const sessionOptions = {
name: 'name of keyboard cat', // Don't use default session cookie name.
secret: 'keyboard cat', // Change it!!!
resave: false, // Resave even if a request is not changing the session.
saveUninitialized: false, // Don't save a created but not modified session.
cookie: {
secure: true, // should be true to check that we´re using HTTPS
httpOnly: true, // dont allow client script messing with the cookie
maxAge: 3200, // will live for 1 day
sameSite: 'lax' // protect against csrf-attack?
}
}
Extended Validation (EV)
Like OV plus more control of the organization that gives
higher thrust