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

Fix #934: :allow may contain namespaced symbols #936

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SCI is used in [babashka](https://github.com/babashka/babashka),
- Fix [#926](https://github.com/babashka/sci/issues/926): Support `add-watch` on vars in CLJS
- Support `aset` on primitive array using reflection
- Fix [#928](https://github.com/babashka/sci/issues/928): record constructor supports optional meta + ext map
- Fix [#934](https://github.com/babashka/sci/issues/934): `:allow` may contain namespaced symbols

## 0.8.43 (2024-08-06)

Expand Down
13 changes: 7 additions & 6 deletions src/sci/impl/resolve.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
:sci.impl/op :resolve-sym
:sci.impl/idx idx))))

(defn check-permission! [ctx sym [check-sym v]]
(defn check-permission! [ctx sym kv]
(or (identical? utils/allowed-loop sym)
(identical? utils/allowed-recur sym)
(let [check-sym (strip-core-ns check-sym)
(let [check-sym (strip-core-ns sym)
allow (:allow ctx)]
(when-not (if allow (or (and (utils/var? v) (not (:sci/built-in (meta v))))
(contains? allow check-sym))
(when-not (if allow
(let [[_ v] kv]
(or (and (utils/var? v) (not (:sci/built-in (meta v))))
(contains? allow check-sym)))
true)
(throw-error-with-location (str sym " is not allowed!") sym))
(let [deny (:deny ctx)]
Expand Down Expand Up @@ -87,8 +89,7 @@
stack)
(->Node
(interop/get-static-fields clazz path)
stack))
))))]))))
stack))))))]))))
;; no sym-ns
(or
;; prioritize refers over vars in the current namespace, see 527
Expand Down
3 changes: 3 additions & 0 deletions test/sci/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@
(is (= 3 ((tu/eval* "(fn [x] (if (> x 1) (inc x)))" {:allow '[fn fn* if > inc]}) 2))))
(is (tu/eval* (str (list `#(inc %) 10)) {:allow '[fn* inc]}))
(is (tu/eval* (str (list `#(let [x %] x) 10)) {:allow '[fn* let let*]}))
(is (= [2 3 4] (sci/eval-string "(impl/mapv inc [1 2 3])" {:allow '[impl/mapv inc]
:namespaces {'impl {'mapv mapv}}})))
(is (thrown-with-msg? #?(:clj Exception :cljs js/Error)
#"allowed"
(tu/eval* "(loop [] (recur))" {:deny '[loop*]})))
Expand All @@ -481,6 +483,7 @@
(is (thrown-with-msg? #?(:clj Exception :cljs js/Error)
#"allowed"
(tu/eval* "(clojure.core/inc 1)" {:deny '[clojure.core/inc]})))

(testing "for/doseq are macroexpanded properly"
(is (= 'loop* (first (tu/eval* "(macroexpand '(doseq [i [1 2 3]] nil))" {}))))
(is (= 'let*
Expand Down
Loading