
(Open Worldwide Application Security Project)
(Common Weakness Enumeration)
Not validating user input fields for unsafe characters
Picture source: Web security for developers
Not validating user input fields for unsafe characters
Picture source: Web security for developers
sanitize-html
import sanitizeHtml from 'sanitize-html';
const html = "<strong>hello world</strong>";
console.log(sanitizeHtml(html));
console.log(sanitizeHtml("<img src=x onerror=alert('img') />"));
console.log(sanitizeHtml("console.log('hello world')"));
console.log(sanitizeHtml("<script>alert('hello world')</script>"));
// Allow only a super restricted set of tags and attributes
const clean = sanitizeHtml(dirty, {
allowedTags: [ 'b', 'i', 'em', 'strong', 'a' ],
allowedAttributes: {
'a': [ 'href' ]
},
allowedIframeHostnames: ['www.youtube.com']
});
var search = document.getElementById('search').value;
var results = document.getElementById('results');
//unsafe
results.innerHTML = 'You searched for: ' + search;
You searched for: <img src=1 onerror='/* Bad stuff here... */'>
//safe
results.innerText = 'You searched for: ' + search;
{{ data }}
//Vue
<div v-html="htmlData"></div>
////React
return <div dangerouslySetInnerHTML={createMarkup()} />;
//Angular
<div [innerHTML]='<a href="#">Unescaped link</a>'</div>
//Vue
{{constructor.constructor('alert(1)')()}}
<teleport to=script:nth-child(2)>alert(1)</teleport></div><script></script>
<component is=script text=alert(1)>
{{$el.ownerDocument.defaultView.alert(1)}}
Content-Security-Policy: script-src 'self' https://api.foo.com
<meta http-equiv="Content-Security-Policy" content="script-src 'self' https://api.foo.com">
British Airways - 2018
https://www.dooble.com/search?q=tesla
https://www.dooble.com/search?q=<script>alert("hacked!")</script>
Not validating query and search params
//const queryString = window.location.search;
const queryString = sanitize(window.location.search);
const urlParams = new URLSearchParams(queryString);
//document.getElementById('searchValue').innerHTML = urlParams.get("q");
document.getElementById('searchValue').innerText = urlParams.get("q");
https://vulnerable-website.com/?__proto__[evilProperty]=payload
targetObject.__proto__.evilProperty = 'payload';
Object.freeze(Object.prototype);
https://example-website.com/login/home.html?admin=true
https://example-website.com/login/home.html?id=876
Exposure via URL redirect parameters
https://example-website.com/user
https://example-website.com/admin
https://example-website.com/admin_293399288
Exposing web page to non-admin
<script>
let isAdmin = false;
.....
if (isAdmin) {
redirectToPage('/admin_293399288');
setHeaderText("Welcome To Admin Page");
}
</script>
U.S. Department of Defense website - Sept 2020
Avoid exposure of secrets and credentials
<!-- Use the DB administrator password for testing: f@keP@a$$w0rD -->
// or in script
const myS3Credentials = {
accessKeyId: config('AWSS3AccessKeyID'),
secretAcccessKey: config('AWSS3SecretAccessKey'),
};
Picture source: Microsoft learn
try {
//code
} catch(error) {
console.log(error);
}
Picture source: tutorial.eyehunts.com
try {
//code
} catch(error) {
console.log("There seems to be an error!");
}
Node js libraries hiding crypto miners - Oct 2021
npm audit
npm outdated
Sanitize data from 3rd party data or API's
LinkedIn: Mariam Reba Alexander