News for hackers. Stuff that matters.
Re:How to gain code execution on hundreds of millions of peo... by TZubiri on Friday February 28, 2025 @09:13PM (#43214869)
Question.

I've noticed a lot of websites import from other sites, instead of local.

<script src="scriptscdn.com/libv1.3">

I almost never see a hash in there. Is this as dangerous as it looks, why don't people just use a hash?

Re:How to gain code execution on hundreds of millions of peo... by bastawhiz on Friday February 28, 2025 @09:38PM (#43215079)
1. Yes

2. Because that requires you to know how to find the hash and add it.

Truthfully the burden should be on the third party that's serving the script (where did you copy that HTML in the first place?) but they aren't incentivizes to have other sites use a hash.

Re:How to gain code execution on hundreds of millions of peo... by valenterry on Friday February 28, 2025 @11:20PM (#43215841)
Well, to be honest, the browsers could super easily solve that. In dev mode, just issue a warning "loaded script that has hash X but isn't statically defined. This is a huge security risk. Read more here" and that's it. Then you can just add the script, run the site, check the logs and add the hash, done.
Re:How to gain code execution on hundreds of millions of peo... by sirl1on on Saturday March 01, 2025 @01:36AM (#43216571)
You can define a CSP header to only exec 3rd Party scripts with known hashes
Re:How to gain code execution on hundreds of millions of peo... by valenterry on Saturday March 01, 2025 @01:48AM (#43216636)
But that doesn't make it easy to integrate a new script from an author who doesn't provide the hash already.
Re:How to gain code execution on hundreds of millions of peo... by no_wizard on Saturday March 01, 2025 @03:14PM (#43223196)
Vendor your dependencies. It’s better for you as a maintainer anyway, since caching only works[0] with first party domains with any reliability.

And once you vendor your dependencies you can calculate the hash yourself

[0]: there are caveats to this

Re:How to gain code execution on hundreds of millions of peo... by TZubiri on Saturday March 01, 2025 @04:45PM (#43224017)
How would third party distribution like a cdn affect hashing?

I think https and integrity hashes address two very orthogonal attack vectors.

Re:How to gain code execution on hundreds of millions of peo... by no_wizard on Saturday March 01, 2025 @07:37PM (#43225822)
It’s about control foremost. If you vendor your dependencies you know what you’re serving and can calculate the hash and use it in your CSP, and provides more stability for versioning.

Plus, as mentioned, only 1st party origins enjoy any benefits of caching content for faster load times so you get an additional benefit

Re:How to gain code execution on hundreds of millions of peo... by 0xCMP on Saturday March 01, 2025 @07:08PM (#43225596)
Because if you're not getting the real benefit (improved response times due to caching) you can stop worrying about hashing it properly or not and simply serve a copy you know to be good (or at least known and probably version controlled). Now you don't need to hash or know which hash is correct or worry about the user getting served the wrong file because someone else got hacked.
Re:How to gain code execution on hundreds of millions of peo... by TZubiri on Saturday March 01, 2025 @07:20PM (#43225702)
Not sure I follow, how does hashing mean you lose improved response times or caching?

Do you mean that hashing the file takes time? I guess that can be significant, but it's probably 2 or 3 cycles per byte, and average js size is like 10kb tops? 30khz doesn't look like much, it's a millionth of a second.

Re:How to gain code execution on hundreds of millions of peo... by 0xCMP on Sunday March 02, 2025 @03:18PM (#43234586)
No, the hashing either when generating or checking is very fast like you said. Hashing itself isn't the culprit, but the battle between browsers and those fingerprinting users.

Originally the point of using a shared CDN like this was that if others used it too the file would already be cached on the user's computer and make it even faster. But, this feature was used for fingerprinting users by checking which files from other websites were cached and browsers have isolated the caches in response which makes it impossible to get the speed benefits from before.

So if you're not getting that speed benefit, and only really getting a tiny bandwidth reduction, the risks of serving the file from a 3rd party (which could be mitigated by the hashes) aren't worth it compared to simply vendoring the file and serving it yourself.

So it's not that hashing prevents caching or lowers response times, but that the risk it is mitigating isn't worth the effort. Just 'err on serving the file yourself.

Re:How to gain code execution on hundreds of millions of peo... by TZubiri on Saturday March 01, 2025 @04:43PM (#43224007)
But you can .. get the hash yourself?

wget url; sha256 file

Re:How to gain code execution on hundreds of millions of peo... by valenterry on Sunday March 02, 2025 @12:31AM (#43227717)
Of course you can. But when it comes to security, one thing is very important in practice: making the secure way of doing things as easy as possible.

So, why did you not actually post the correct shell script? Apparently that would have been more effort to get right and ensure is correct right? And also work for every OS. And there you have it: if someone first has to figure out which script to run, some percentage will give up here. And that's my point: the browser should make it as easy as possible to avoid that from happening.

Re:How to gain code execution on hundreds of millions of peo... by account42 on Tuesday March 04, 2025 @07:27AM (#43253664)
Cool. Now your site will break if the upstream pushes a fix while you're on vacation.
Re:How to gain code execution on hundreds of millions of peo... by bastawhiz on Sunday March 02, 2025 @05:46PM (#43236077)
> In dev mode, just issue a warning "loaded script that has hash X but isn't statically defined.

How does the browser know which files to warn you about? What about scripts that are generated dynamically and have no static hash? There's plenty of reasons why you wouldn't want this.

Re:How to gain code execution on hundreds of millions of peo... by valenterry on Monday March 03, 2025 @01:46AM (#43238987)
It just warns about all embedded non-same-origin scripts that don't have a hash.

> What about scripts that are generated dynamically and have no static hash?

Well, then the warning is still valid because this is a security risk. I guess it'd be fine to be able to suppress the warning explicitly in those cases.

> There's plenty of reasons why you wouldn't want this.

For example? Honestly curious where you would not want a warning by default.

Re:How to gain code execution on hundreds of millions of peo... by quacksilver on Saturday March 01, 2025 @05:08AM (#43217805)
I wish popular browsers would get together and release an update that says:

- After version X we are displaying a prominent popup if a script isn't loaded with a hash

- After version Y we blocking scripts loaded without hashes

They could solve this problem in a year or so, and if devs are too lazy to specify a hash when loading scripts then their site will break.

Re:How to gain code execution on hundreds of millions of peo... by TZubiri on Saturday March 01, 2025 @04:47PM (#43224045)
I don't think it's just laziness. There's use cases where the libraries are designed to be updated automatically.

Also some of the tracking scripts I don't think are strictly static content, maybe their strategy to fingerprint browser involves sending different shit to different users.

Re:How to gain code execution on hundreds of millions of peo... by quacksilver on Monday March 03, 2025 @04:00AM (#43239804)
If you are the one serving the website, then you are the one generating the hash. If you want to serve different stuff then you could dynamically generate the hash for that different stuff rather than hard code it statically.

Specifying a script hash says that you as the owner of that site agree to load the content only if it matches the hash. Presumably you trust the content enough to serve it to your users.

Re:How to gain code execution on hundreds of millions of peo... by bastawhiz on Sunday March 02, 2025 @05:48PM (#43236095)
Literally every website that uses JSONP will stop working if that happened. This would break the web in fundamental ways. If we're going to break the web in fundamental ways, resource integrity is hardly among the things that I'd be interested in changing.
Re:How to gain code execution on hundreds of millions of peo... by quacksilver on Monday March 03, 2025 @04:09AM (#43239863)
Why would people choose JSONP over CORS?

There are security risks with JSONP (a hack to bypass same-origin policy), and the successor (CORS) has been around since 2009, so phasing it out may be a good thing.

https://dev.to/benregenspan/the-state-of-jsonp-and-jsonp-vul...

Re:How to gain code execution on hundreds of millions of peo... by account42 on Tuesday March 04, 2025 @07:28AM (#43253680)
Good. JSONP requests to a domain you don't control are a security nightmare.
Re:How to gain code execution on hundreds of millions of peo... by valenterry on Friday February 28, 2025 @11:19PM (#43215829)
Yes it is. Hashes must absolutely be used in that case.
Re:How to gain code execution on hundreds of millions of peo... by LtWorf on Saturday March 01, 2025 @01:45AM (#43216620)
It should just not be done at all. But the main browser vendor loves tracking so they won't forbid this.
Re:How to gain code execution on hundreds of millions of peo... by valenterry on Saturday March 01, 2025 @01:49AM (#43216643)
Maybe, but just from a security point of view it's totally fine.
Re:How to gain code execution on hundreds of millions of peo... by LtWorf on Saturday March 01, 2025 @02:05AM (#43216718)
Getting tracked is less secure than not getting tracked.
Re:How to gain code execution on hundreds of millions of peo... by SideQuark on Saturday March 01, 2025 @03:43AM (#43217352)
Getting hacked is less secure than getting tracked.
Re:How to gain code execution on hundreds of millions of peo... by LtWorf on Saturday March 01, 2025 @06:49PM (#43225421)
Very clever. But getting tracked doesn't in any way protect you from getting hacked. It just exposes you to more risks, including getting hacked.
Re:How to gain code execution on hundreds of millions of peo... by valenterry on Saturday March 01, 2025 @06:09PM (#43224955)
Fair enough.
Re:How to gain code execution on hundreds of millions of peo... by Thorrez on Saturday March 01, 2025 @08:51AM (#43219229)
Are you saying Chrome should block all script includes that don't have hashes? That'll break tons of sites. See "Don't break the web"[1].

Disclosure: I work at Google, but not on Chrome.

[1] https://flbrack.com/posts/2023-02-15-dont-break-the-web/

Re:How to gain code execution on hundreds of millions of peo... by LtWorf on Saturday March 01, 2025 @06:50PM (#43225430)
Also expired certificates break a lot of websites… should we disable checking?
Re:How to gain code execution on hundreds of millions of peo... by ameliaquining on Saturday March 01, 2025 @09:50PM (#43226685)
Certificate expiration isn't an unanticipated regression. You know when you get a certificate when it will expire.
Re:How to gain code execution on hundreds of millions of peo... by hyperdimension on Sunday March 02, 2025 @01:18PM (#43233283)
I don't mean to be pedantic, but not always--see the recent DigiCert delayed revocation issues. I will admit it is rare though and more often than not, you (should) know when your certs are going to expire.
Re:How to gain code execution on hundreds of millions of peo... by Thorrez on Sunday March 02, 2025 @09:44AM (#43230939)
Those websites set up the expiring certificate themselves.