Weaponize your package
@naugtur, The Hack Summit 2024
π¦π
So you want to attack someone with a malicious package
In general, disguise it as one of these
## Prototype poisoning
# π§ͺπ
![]()
```js
const a = {};
Object.prototype.toString = ()=>'π»';
console.log(`scary object: ${a}`);
```
```
scary object: π»
```
### JS can be tweaked and it's no accident
- designed in 10 days
- humbly assuming there's room for improvement
## polyfills
#### and
## prototype poisoning
#### are the same thing
#### with different intentions
# βοΈ
## a weapon
```js
Object.defineProperty(Object.prototype, "Authorization", {
set(value) {
console.log(`stolen: ${value}`);
},
});
```
```js
const headers = {};
if( authorized ) {
headers.Authorization = `Bearer ${token}`;
}
```
## attack examples
[repo](https://github.com/naugtur/js-training-examples/tree/master/websec101/attacking)