clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
souenzzo 2021-06-24T00:26:04.387400Z

Is possible to write a macro like this but that "emits" (+ 1 42) ? (will return 43, but this should not be done at macro time)

(defmacro unquote-test
  [form]
  form)
(def a 42)
(unquote-test (+ 1 ~a))

souenzzo 2021-06-24T11:18:04.390800Z

There is no helper to "eval all unquote"?

phronmophobic 2021-06-24T17:19:25.401900Z

not sure what you're asking

phronmophobic 2021-06-24T00:44:04.387500Z

(defn unquote-test* [form]
  (clojure.walk/postwalk (fn [form]
                           (if (and (seq? form)
                                    (= (first form)
                                       'clojure.core/unquote))
                             (eval (second form))
                             form))
                         form))

(defmacro unquote-test
  [form]
  (unquote-test* form))

(def a 42)

(unquote-test (+ 1 ~a))
;; 43

(macroexpand '(unquote-test (+ 1 ~a)))
;; (+ 1 42)

Elso 2021-06-24T09:35:02.388700Z

is there a way to dynamically access pre/post-conditions?

Elso 2021-06-24T09:35:37.389300Z

I see that they just translate to assertions in the fn macro

Timofey Sitnikov 2021-06-24T11:01:03.390600Z

Good morning All. I am attempting to handle password management. It requires 3 fields, (hash, salt, iterations). I am using Postgres, should I keep the fields as part of account table and update! the account fields, which is mutable approach, or should I add a password table and use it as a write only immutable table? This is not an objective question, but I would like to get your input.

p-himik 2021-06-24T11:29:03.391100Z

Why would you need a history of password hashes?

p-himik 2021-06-24T11:29:37.391300Z

And by "write only" I guess you meant "append only".

vemv 2021-06-24T11:41:01.391500Z

Yeah it looks like there's no :pre/:post meta on a given defn's var. You could parse instead the output of clojure.repl/source

Timofey Sitnikov 2021-06-24T12:30:18.391700Z

@p-himik, this is exactly my hesitation. This is what Rich Hickey seems to Advocate. I am having a hard time seeing it but it does simplify the code and it does add to history of user. Would it be useful? Its difficult to know.

dharrigan 2021-06-24T13:09:24.392Z

It's not that normal to store the password hash, iteration and salt separtely.

βž• 1
dharrigan 2021-06-24T13:09:35.392200Z

they are normally part of the hashed password

dharrigan 2021-06-24T13:09:36.392400Z

i.e.,

dharrigan 2021-06-24T13:09:44.392600Z

echo -n "foobar" | argon2 $(date +%s) -t 300 -p 2 -e
$argon2i$v=19$m=4096,t=300,p=2$MTYyNDU0MDE2MA$dd3roHwKqQI9uFVkgzNk/UKeQI104Uk8I4iIDwrftOM

dharrigan 2021-06-24T13:10:06.392800Z

so the hash, i.e.,

dharrigan 2021-06-24T13:10:17.393Z

$argon2i$v=19$m=4096,t=300,p=2$MTYyNDU0MDE2MA$dd3roHwKqQI9uFVkgzNk/UKeQI104Uk8I4iIDwrftOM contains the salt, iterations etc...

dharrigan 2021-06-24T13:10:44.393200Z

I've never had to store a history of hashes

dharrigan 2021-06-24T13:10:59.393400Z

which would open up a security risk, for if someone had the history of all the passwords that someone had....

p-himik 2021-06-24T13:11:47.393600Z

@timofey.sitnikov Rich argues that being able to see data history is useful. I would add to that that passwords are not data in that sense. Credentials are a means to access something right now. I cannot see how history of credentials could be useful, but I can definitely see how such a history could potentially be a hole in security.

πŸ‘ 2
p-himik 2021-06-24T13:12:29.393800Z

And also what dharrigan said about storing all the hash parts together.

Timofey Sitnikov 2021-06-24T14:51:46.394300Z

Thank you all, that makes sense.

jdkealy 2021-06-24T15:25:12.395700Z

I have a strange case where i'm trying to consume form-params that were encoded as JSON, no middleware seems to be able to parse it, i'm getting {:form-params {}} on everything i try

jdkealy 2021-06-24T15:48:57.396100Z

the content type says application/x-www-form-urlencoded i can see the payload being sent from salesforce, but no dice

Apple 2021-06-24T16:04:39.396500Z

https://github.com/metosin/muuntaja can help

jdkealy 2021-06-24T16:07:16.397Z

i was already using that...

jdkealy 2021-06-24T16:07:46.397400Z

i ended up making a conditional middleware based on the route that parses the body using slurp

Apple 2021-06-24T16:20:02.398300Z

can you try to dump the whole request map?

valtteri 2021-06-24T16:26:41.398800Z

One reason for keeping history of password hashes is to prevent reusing passwords. It used to be a OWASP best practice.

p-himik 2021-06-24T16:39:34.399100Z

Makes sense. However, seems like they have redacted that recommendation? ASVS v3: "2.25 Verify that the system can be configured to disallow the use of a configurable number of previous passwords." ASVS v4: "2.1.10 Verify that there are no periodic credential rotation or password history requirements."

Ed 2021-06-24T16:45:46.399400Z

are you consuming the input stream before passing it to the middleware? for example, printing it for debugging? the request input stream that you get in the body of the request can only be processed once, so it'll need to be captured to be processed again

valtteri 2021-06-24T17:13:13.399600Z

My knowledge might be outdated. πŸ™‚

pez 2021-06-24T17:17:52.401200Z

I ran across a weird thing. Is this supposed to be a valid complete Clojure file?

#_ #?(:clj :foo)

valtteri 2021-06-24T17:18:31.401500Z

Edited my comment

pez 2021-06-24T17:19:20.401700Z

If I have this in CLJC file, the shadow-cljs compiler errors with EOF while reading.

alexmiller 2021-06-24T17:20:04.402300Z

that makes sense to me -there is nothing to read

2021-06-24T17:20:14.402500Z

I would guess yes if you were reading it using the Clojure reader, but no if you are reading it using ClojureScript reader

2021-06-24T17:20:57.402700Z

how do each of the compilers treat an empty file? because that fragment should be treated as if it were a lack of input

2021-06-24T17:21:49.403Z

Well, for ClojureScript it is treated as if the file contained #_ and nothing else, yes? And that is probably why it is giving EOF, because the reader is not finding any following expression to omit

alexmiller 2021-06-24T17:22:14.403200Z

in both cases, read can't return you anything

2021-06-24T17:22:54.403400Z

I don't know about ClojureScript compiler, but the Clojure compiler has a pretty easy time with an empty file πŸ™‚

alexmiller 2021-06-24T17:23:44.403600Z

depends if you're talking about load or read

alexmiller 2021-06-24T17:30:09.403800Z

something like (read-string {:read-cond :allow} "#_ #?(:clj :foo)") is going to throw with EOF as there is nothing to read and return. load is going to read and eval until it hits EOF, so it will just read nothing and stop.

valtteri 2021-06-24T17:30:22.404Z

Hmmm.. I’m a bit confused. In the stable version they still include checking previous passwords in #4 https://owasp.org/www-project-web-security-testing-guide/stable/4-Web_Application_Security_Testing/04-Authentication_Testing/07-Testing_for_Weak_Password_Policy > How often can a user reuse a password? Does the application maintain a history of the user’s previous used 8 passwords?

p-himik 2021-06-24T17:42:07.404300Z

Seems like ASVS != WSTG. Why they seemingly conflict on this particular matter, I have no clue.

pez 2021-06-24T17:54:45.405400Z

How is it different from #_ :foo?

pez 2021-06-24T17:59:57.405700Z

My file looks like so:

(ns ...)
#_ :foo
#_ :bar
#_ #?(:clj :foo)
#_ :baz
And only the line with the reader conditional causes the EOF.

p-himik 2021-06-24T18:14:49.406100Z

To go back to the original topic. If I had to implement old password reuse prevention mechanism, I would go with a separate table that has nothing to do with authentication. It would store only old passwords' hashes and would be used only when a user is trying to change their password. The current password's hash would still be in the same table as the main user information.

2021-06-24T18:21:40.406400Z

I think it is the same as reading a file with just this #_

eskos 2021-06-24T18:38:47.409600Z

Would be nice if the error in this case would be something like "no form after # to skip_"

pez 2021-06-24T18:49:53.410400Z

Thanks @suomi.esko , now I get it. 🀦

thiru 2021-06-24T20:38:04.413900Z

Hey folks. I recently joined a data science team. They're using Spark with Python to process their larger datasets (TBs, PBs). What do Clojure folks use for this use case? I see there's the Sparkling library but it hasn't had commits in over a year and it's not currently REPL friendly. I also came across Thurber but it is specific to Google's DataFlow and our company is all in with AWS.

greglook 2021-06-24T21:11:10.414100Z

We wound up writing a new library (similar to sparkling) which we use in production for our big data processing jobs. https://github.com/amperity/sparkplug

πŸ‘ 1
πŸ’― 1
greglook 2021-06-24T21:11:57.414400Z

Some of it (like the ML stuff) is incomplete, but the core APIs are all supported.

thiru 2021-06-24T22:54:50.414700Z

Oh sweet, I'll definitely take a look. Thanks!