-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is confused deputy attacks
are really harmful?
#12
Comments
I seen this quite a few time mentioned as problem of Because, I see this as replacement for a lot of const someRelations = new WeakMap();
class A {
set relation(obj) {
someRelations.set(this, obj);
someRelations.set(obj, this);
}
get relation(obj) {
return someRelations.get(this);
}
} Replaced with: const someRelation = Symbol.private();
class A {
set relation(obj) {
this[someRelation] = obj;
obj[someRelation] = this;
}
get relation(obj) {
return this[someRelation];
}
} And lets imagine shorthand syntax for class A {
private #someRelation; // creates `Symbol.private` referenced by `#someRelation` constant
// and defines `#someRelation` property on `A` instances
set relation(obj) {
this.#someRelation = obj;
obj.#someRelation = this;
}
get relation(obj) {
return this.#someRelation;
}
} Isn't it looks nice? There are a lot of other use-cases (especially in game development), where we want to install some |
I think it can be both. Sometimes you want to be able to initialize late, sometimes you don’t. It’s only when you don’t that it becomes “confused deputy.” In the PNLSOWNSF take, late* initialization appears to be served. My interpretation of the objection is that private symbols are considered to make unintended late initialization into a footgun. Personally, I do continue to prefer private symbols, but I thought PNLSOWNSF presented an interesting compromise: minor concession in ergonomics for the private symbol camp, but with their needs still served; no concession for the current private fields proposal.
|
I think the term "confused deputy attack" is a bit... confusing. Another way to describe these sorts of issues is, "Some code looks like it does something, but actually it does something else, as a result of interaction with a third thing." Private fields and methods are designed to be reliable, and have semantics that you can predict by looking at a relatively small, local amount of code. The amount of code you have to examine to figure out what's going on is larger for private symbols than with the WeakMap semantics (but, in both cases, it's way smaller than using ordinary properties). In general, interactions and reliability are is a serious thing to consider, but we won't land at the conclusion that we should prohibit that interaction every time. I understand and respect @erights' impulse to start from a default of discouraging or disallowing these interactions--something you could use the fancy acronym "Principle of Least Autority" (POLA) for. Maybe we do want to support the interactions, but we should understand why. |
We, already talked about reasons behind allowing such interactions dozens of time, bu I'll shortly summarize main points:
@littledan, I know that you probably tired of discussion like this, but this statement kinda misleading
I would love this to be true. And if it could be so, I would be ok with
So this is trade-off. From my perspective it looks like this: class Foo {
#state;
...
setState(newState) {
this.#state = newState;
}
}
const f = new Foo();
const notAFoo = {};
f.setState.call(notAFoo); By dropping: const f = new Foo();
const notAFoo = new Proxy(f, {
// some pretty complex relation tracking Proxy implementation, like this (very simplified) example
// https://github.com/Igmat/metaf/blob/develop/packages/core/src/atom/index.ts
});
f.setState.call(notAFoo); I don't understand why the first is so important, because:
@erights, as far as I understand you're the main proponent of providing IMPLICIT brand-check by default (and @littledan was referring to you few times). Could you please clarify and/or answer to previous question? Is it possible for you to provide some really important case when brand-check is required (ideally from common developer perspective)? P.S.@erights, don't you see that your last example in your documentation behaves EXACTLY in same way as |
The text was updated successfully, but these errors were encountered: