Skip to content
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

Should collections be prevented from being used as functions? #443

Open
helins opened this issue Dec 22, 2022 · 3 comments
Open

Should collections be prevented from being used as functions? #443

helins opened this issue Dec 22, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request question Further information or discussion is requested

Comments

@helins
Copy link
Member

helins commented Dec 22, 2022

E.g.

({:a :b} :a) ; -> :b

This construct is quite typical in function programming and Clojure does it as well. However, in :callable? function, this can very easily lead to code injection. Something so dangerous should probably not be so easy. It might be wiser to entirely remove this capability.

@helins helins added the question Further information or discussion is requested label Dec 22, 2022
@mikera
Copy link
Member

mikera commented Dec 23, 2022

The main argument I can see for keeping this is the convenience of allowing certain higher order functional programming constructs e.g.:

  • A Set being passed as a predicate to a filtering operation
  • A Map being passed as a lookup function

With some static analysis, it should be easy to see if an untrusted input is being used in a dangerous position like this, but I agree it is definitely a risk that people need to be aware of. Unclear I think if we should remove this feature or somehow add some extra protections.

@helins
Copy link
Member Author

helins commented Dec 23, 2022

In my experience, I have seldom needed to use sets and maps like that, even in Clojure. It does happen but not often. Not to the point where we should feel compelled to optimize the language for if it can clearly lead to detrimental effects.

Passing (fn [x] (get m x)) is those rare situations seems a minor inconvenience in comparison to the disasters it might prevent.

Not decided yet but balancing towards removal so far 🤔

@mikera mikera added the enhancement New feature or request label Dec 28, 2022
@mikera mikera self-assigned this Dec 28, 2022
@mikera
Copy link
Member

mikera commented Dec 28, 2022

I think I'm leaning towards removal too. A bit too dangerous.... Code injection via data is a real risk equivalent to eval

Only slightly strange thing is what to do with keyword accessors which use the same pattern i.e. (:field some-map). Probably needs to be a compiler special case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information or discussion is requested
Projects
None yet
Development

No branches or pull requests

2 participants