-
Notifications
You must be signed in to change notification settings - Fork 113
[Private] Metaprogramming vs Security #134
Comments
If you're going to use As for "don't like OOP paradigm in general", that's both untrue and irrelevant. |
@Igmat You've made a few mistakes that may alter what you're trying to achieve here.
True but irrelevant. Everyone I know of in these debates has accepted that
Sadly true, but also irrelevant. The fact that developers are accustom to the
Patently false. None of the standing counter-proposals allow a private field to be publicly accessed. |
@ljharb, it was offtopic from your side, but since I mentioned you directly, I'll answer - and I hope, you'll continue in more proper way for technical discussion. It's only one of several advantages and even more - it's only a small part of one of several advantages (there could be other access levels, that we'll want/need). Since I read dozens comments from you and found nothing constructive about I believe you're great professional, and obviously you're part of the committee (while I'm - not), but it doesn't make your own opinion more valuable than mine or anybody's else, if you don't provide proper argumentation. You don't own this language to behave like that. |
I'm not the only one who hasn't accepted it - there are plenty of developers who would prefer While I could easily accept
This looks like paraphrasing my argument against
Obviously, probably I didn't explain it clear enough. I didn't meant that somebody proposed |
@Igmat Ok. I get that there are those who still want to see
So I get it, but the TC39 board has defined what they want on this very clearly, and that's both inaccessibility and undetectability. I think their overdoing it, but they won't budge on this issue. So it's fair to say that no proposal including detectability of private fields will pass.
The problem with the symbol-based approach is that if the symbol is leaked, so is access. Even the possibility of leaking access is a big NO for any private field proposal.
You missed the last line of that paragraph. What I'm saying is that the (
Wherein this proposal restricts accessibility, it's pretty thorough. I won't say that all edge cases have been found, but I have yet to find one that hasn't been handled. I'm sure @bakkot, @littledan, & @ljharb would all appreciate an example of an edge case you think they missed if you have one. |
@rdking probably I wasn't clear enough, but my proposal requires another kind of symbols (like in this proposal), that leads to somewhat other conclusions. I won't repeat whole proposal about
So this:
is irrelevant.
because for now it also seems to be irrelevant.
The only way how private symbol could leak in my proposal is following: class A {
private somePrivate;
method() {
return somePrivate;
}
} If that is a problem (which I'm not sure yet), it could be restricted, causing Syntax or Reference error, unless class A {
private somePrivate;
private method() {
return somePrivate;
}
}
Could you please clarify which kind of mistake will developer make with syntax proposed in this topic? To be honest, I'm pretty satisfied by Difference in terms of Security between my proposal and existing in this repo as Stage3 is on simple trade-off:
IMO it's reasonable trade-off, because implementing my proposal keeps EXISTING option for |
To prove my point just try to google |
And one more. I realized that I've seen here a lot of quotes like this "let's use decorators for other kinds of access levels". From my point of view it seems to be a strong argument against adding unnecessary feature directly into language, which also breaks something that is heavily required by community. |
@Igmat you might be interested in #115.
Not true at all. The private symbol could be:
There's probably other ways as well, but this should be enough to show how easily they can be leaked.
That would be counter-productive and unnecessarily increase the amount of code required. The better approach would be to require that only member functions present in the Right now, in #133, I'm discussing with @bakkot an alternate approach to this proposal that resolves the proxy issue without significantly altering much else about the proposal. We haven't reached that point in the discussion yet since he seems to have a severe hang-up regarding the possibility of developers accidentally generating a public field when they meant to access a private one. The suggestions I'm offering show neither of the "trade-offs" you've mentioned without giving up anything else. |
My proposal is syntax sugar for using
Yeap, definitely, I meant that leaking of private symbols could happen ONLY if code author will explicitly do it. Risk that it will happen unintentionally is nearly the same as risk of unintentional returning of private value. |
In the most recent TC39 meeting, we considered an alternative proposal, Private Symbols, which have a somewhat weaker sense of undetectability. The committee decided that a very strong sense of undetectability is an important feature of private fields. At this point, implementations are moving forward with the private fields proposal in this repository; see the README for details. |
@littledan I've already checked data about latest meeting, you had wrong assumptions in your presentation, while I haven't seen what was discussed as alternative. |
@lgmat What assumptions were wrong? |
@littledan
Personally I don't like |
|
@littledan, sorry. I'm obviously not a native speaker for English, so I'm curious is the way I'm expressing my concerns and issues about this proposal unclear? I'm asking, because your (committee's) answers sometimes sound like talking with a baby - and it confuses me.
The only reason (BTW it's unexpressed) to continue with existing proposal is the fact that it's already implemented! Everybody will use private for encapsulation and everybody will suffer from the fact that they have to choose between metaprogramming proxies or ecapsulated (and implicitly |
I guess there may be some misunderstandings in TC39 members.
But there are still many other reasons why many experienced js programmers disagree this proposal. You can't say the main concern of them is syntax just because they also dislike And even the disagreements purely to It's also add the distrust between the community and the committee which I think may have a negative far-reaching influence to all of us. And it's already begun. |
There is a chance --- classes 1.1 with the shorthand extension. I don't want to say it's a perfect solution now but I believe there is a possibility we could investigate and find a much better and acceptable syntax in this path. |
@hax The problem is that TC39 is holding fast to their "undetectability of private fields" requirement. The only way to accomplish this is to let the syntax for accessing a private field be distinct from the syntax for accessing a public field. Unless someone can convince them that this requirement is pointless, my statement stands. I've pointed out the logical contradiction of this requirement, but that contradiction has been ignored. So good luck. |
@rdking I know the requirement of "undetectability", and shorthand syntax of class 1.1 satisfy this with |
My big concern about At a higher level, the objections to this proposal have been going in several different directions. For example, if we did a longer investigation into 1.1, we wouldn't get any closer to satisfying people who want more metaprogramming mechanisms. I think we have a strong reason for all the decisions in the current proposal. |
There are alternatives of And I even have some other idea which can eliminate any possible confusion between
Unfortunately |
@hax You're not alone in thinking that dismissive opinion has been unevenly applied. This is a proposal I've been working on that includes the best features of the current proposal while removing many of the major issues like Proxy failure, @littledan Even if it will never see the light of day, I would still like to see the proposal I've offered get at least as much coverage as the 1.1 proposal. While it's true that the main visible difference is the syntax, as has been stated many times before, the syntax reflects what is actually going on under the hood. So changes to the underlying mechanism will necessitate changes to the syntax. |
@rdking Yeah, we share many opinions about current proposal 😄 , though we may still have different views on what is a better proposal should be. For example, your Anyway, in this issue list, I feel your comments are always enlightening. So I hope I can hear your comments on classes 1.1 . What is your biggest concern on it? You can create issue on https://github.com/zenparsing/js-classes-1.1/issues and @ me.Thank you! |
@hax I have never claimed that my proposal is better than the 1.1 proposal (that I can recall). My only claim is that my proposal is in keeping with almost everything that the TC39 has agreed upon with regards to the current proposal without suffering any of its unnecessary drawbacks. The 1.1 proposal, while not bad, would reset the discussions back to the beginning again. That's not a bad thing either, but I don't think the board is willing to do that.
With my proposal, Like I've stated before, the goal with my proposal is to make minimal changes to the current proposal so that we don't have to start all over from the beginning and lose the benefits of the many discussions that lead to the current proposal. Like the 1.1 proposal I want a complete implementation of I'll look through 1.1 and throw some comments on that. But for now, I'm of the impression that the reason we're all coming up with such disparate proposals is because we're trying to do some that doesn't yet make sense in the context of a |
I was kinda late to this discussion since it's already
Stage 3
, but still there is a hope that some decisions could be revisited.I've carefully read FAQ and some related discussion, like #100, #106, #122 and others plus a lot of links, including other syntax proposals, that were mentioned there.
Probably I missed something (there are TOO many discussions and ideas and it's non-trivial task to cover all of them, if it isn't part of your day-to-day work), but it seems that I've finally found core misunderstood between committee and community. From my point of view broken proxies (#106), when target uses
#
-privates and proxy author (probably some framework/library maintainer) can't control full class and instance lifecycle is a HUGE limitation to how we can apply metaprogramming patterns to ES real-world applications and reason why this happens is security, whichde-facto
was a hard requirement forprivates
but wasn't clearly articulated to community. (if you're intersted I can try to find comments that lead me to such conclusion)#
-syntax proposal advantagesa. I (as code author) can safely pass an object built with my class to untrusted execution context, knowing that there is no way to read or even examine its private properties
b. Nobody can apply my methods to something that isn't instance of my class if those methods use privates (somewhere it was mentioned as
brand
-check)private
-keyword syntax disadvantagesprivate somePrivate;
and access -this.somePrivate
, then property lookup will become VERY difficult, untrivial and probably unsecureOR
private somePrivate;
and accessthis.#somePrivate
orprivate(this).somePrivate
or whatever that not justthis.somePrivate
it will lead to one of the following:a. Silent bugs:
SyntaxError
, anybody outside could examine object's privates at least for their names, sinceconst a = new A(); a.somePrivate;
outside class definition is the same asthis.somePrivate
somewhere in class definition.All of the above is good motivation (assuming that security is more important) to choose
#
-syntax, even though it leads to HUGE limitation of metaprogramming using proxies (#106).Initially my motivation for writing this post was to find out the reason of such misunderstood between community (I believe I'm a part of community too) and committee.
While thinking about it I also tried to find simplest solution for problem described in #106, because it relates to HUGE amount of developers directly (Evan (@yyx990803), Rob (@EisenbergEffect) as maintainers of popular projects that want to use proxies for implementing proper reactivity and me as person who experiments with metaprogramming capabilities for kinda same purposes) or indirectly (developers who want/need frameworks/libraries/tooling that provides such higher-order functionality).
Reading issues in this repo I've found out that security pattern based on WeakMap was taken for implementing
private
proposal. But what if we'll take another approach, based on Symbols and closures.Syntax
Such kind of syntax doesn't have disadvantages mentioned above, because based on existing property lookup mechanism and existing closures securing.
But it doesn't have advantages of
#
-sigil based syntax, since usual Symbol could be easily found bygetOwnPropertySymbols
and/orProxy
.In order to have same security - it should be another type of Symbol. I've started to collect requirements to such kind of Symbol, but then I've found proposals that actually did it already (like this one https://github.com/zenparsing/proposal-private-symbols, I believe that @zenparsing will describe it better than I can).
Advantages
protected
)PLEASE
Let's try to have constructive discussion, because as we can see (for example in #133) there are a lot of developers that wasn't convinced by committee's arguments.
I, personally, did my best trying to find reasons behind existing proposal, and I hope that committee will do the same for community, especially after @littledan meet some of open-source maintainers in person.
P.S.
@ljharb, we all know that you hate
protected
and don't like OOP paradigm in general, so please don't try to move this topic into discussing whether or not we need it in ES.The text was updated successfully, but these errors were encountered: