Fork me on GitHub
#clojure-europe
<
2022-08-25
>
simongray07:08:41

today’s fun issue: figuring out multiple layers of URI encoding

simongray08:08:58

So now I discovered the cause of my woes… my university’s SAML identity provider covertly decodes the query string that is supposed to be passed back during the login process…. I wonder if a better idea is to encode in some other way… maybe base64?

mccraigmccraig08:08:36

you can't go wrong with an opaque alphanum token! you might have to get rid of b64 = padding, since that get's url encoded - some b64 libs are ok to decode without it though

simongray08:08:09

Hmm.. By = padding do you just mean any equals signs in the encoded value? Can I just search and replace those with some other character?

simongray09:08:30

Looking at https://en.wikipedia.org/wiki/Base64#Base64_table_from_RFC_4648 I guess I will need to replace =, /, and +

mccraigmccraig09:08:35

doh! i'd forgotten b64 can output those chars. if you aren't too worried about token size, you could just hex encode the bytes of your UTF8 url string ... leaving you with just a [0..9]* token

simongray09:08:36

I went with this

(defn safe-base64
  [s]
  (str/replace s #"/|\+|=" {"/" "_", "+" "-", "=" "."}))

(defn unsafe-base64
  [s]
  (str/replace s #"_|-|\." {"_" "/", "-" "+", "." "="}))

(defn safe-encode
  [url]
  (safe-base64 #?(:clj  (codec/base64-encode (.getBytes (codec/url-encode url)))
                  :cljs (js/btoa (js/encodeURIComponent url)))))

(defn safe-decode
  [base64]
  #?(:clj  (-> base64 unsafe-base64 codec/base64-decode slurp codec/url-decode)
     :cljs (-> base64 unsafe-base64 js/atob js/decodeURIComponent)))

simongray09:08:48

seems to work fine! 🙂

👍 1
otfrom07:08:54

I love how I got into coding to escape having to write history essays and now all the coding I do is to create evidence for (speculative) history essays and present them to people. I went wrong somewhere.

🙂 1
otfrom07:08:04

or studying history is a good background for doing computers

otfrom07:08:07

or something

Ben Hammond07:08:43

> Those who do not study history > are doomed to repeat it

3
otfrom08:08:06

those who do study history are doomed to scream while watching the others repeat old mistakes.

laughcry 2
thomas08:08:40

History is immutable.... maybe that is why I like it so much :thinking_face:

Ben Hammond08:08:27

excision is always an option

🕳️ 3
Ben Hammond08:08:11

theres some truth in that quote about > its never too late to have a happy childhood

simongray08:08:58

So now I discovered the cause of my woes… my university’s SAML identity provider covertly decodes the query string that is supposed to be passed back during the login process…. I wonder if a better idea is to encode in some other way… maybe base64?

otfrom08:08:40

our understanding of history is very mutable as we are lacking the details of lots of the events though

💯 1
reefersleep12:08:29

And historians are biased. It’d probably be really interesting to see how specific events in history have been reported differently throughout the years in one country… Or to compare contemporary reports from different countries.

otfrom12:08:49

which is literally what history and historians do. Reading "for bias" and reading "through bias" in primary and secondary sources were the most important skills I learned in history. It does completely change how you look at the news, science and other things that say they are unbiased though.

reefersleep13:08:59

My view is that everyone is biased 🙂 It’s not something one can escape, since you can’t express objective truth. But even without going down that philosophical road, my first thought whenever I hear something is most often “Cui bono?” Why would exalted scientists, news anchors, politicians, policemen… etc be exempt from allowing everyday human desires to influence their actions?

reefersleep13:08:38

A bit bleak, yeah 😕

otfrom13:08:45

Trying to figure out what passes for unbiased, balanced, and objective is a fun bit of analysis for historians.

otfrom13:08:44

I don't find it bleak though. We are here now because of where we were before and what we all did, which opens up lots of possibilities

😍 1
reefersleep13:08:26

Of course. I’m should turn that frown upside down. I tend to think about the negative consequences of important figures acting on desire rather than the positive, which, evidently, are legion

otfrom13:08:27

oh, absolutely

genRaiy09:08:48

Good monochrome

🖤 6
lread12:08:33

goodMorning