Skip to content

Commit f16375e

Browse files
committed
Switch to hiccup2.0 in clojars code base
This change attempts to migrate clojars to the latest version of hiccup, which has introduced a bunch of new security features. In this change, we also remove the old safe_hiccup, as this functionality is built into Hiccup2. #914
1 parent 5b722e1 commit f16375e

File tree

16 files changed

+276
-311
lines changed

16 files changed

+276
-311
lines changed

dependabot/deps-list.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ duct/hikaricp-component 0.1.2 (EPL-1.0)
6767
environ/environ 1.1.0 (EPL-1.0)
6868
fipp/fipp 0.6.29 (EPL-1.0)
6969
funcool/cuerdas 2.2.0 (BSD (2-Clause))
70-
hiccup/hiccup 1.0.5
70+
hiccup/hiccup 2.0.0 (EPL-1.0)
7171
instaparse/instaparse 1.4.8 (EPL-1.0)
7272
io.airlift/aircompressor 2.0.2 (Apache-2.0)
7373
javax.xml.bind/jaxb-api 2.3.0 (CDDL 1.1)

dependabot/deps-tree.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ duct/duct 0.8.2
186186
. medley/medley 0.8.3
187187
. meta-merge/meta-merge 1.0.0
188188
X ring/ring-core 1.5.0 :use-top
189-
hiccup/hiccup 1.0.5
189+
hiccup/hiccup 2.0.0
190190
one-time/one-time 0.8.0
191191
X commons-codec/commons-codec 1.15 :older-version
192192
X ring/ring-codec 1.2.0 :superseded

dependabot/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
<dependency>
167167
<groupId>hiccup</groupId>
168168
<artifactId>hiccup</artifactId>
169-
<version>1.0.5</version>
169+
<version>2.0.0</version>
170170
</dependency>
171171
<dependency>
172172
<groupId>one-time</groupId>

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
:exclusions [org.slf4j/slf4j-nop]}
4040

4141
;; manually imported clj-kondo configs from 2.x branch to .clj-kondo/imports/hiccup/hiccup
42-
hiccup/hiccup {:mvn/version "1.0.5"}
42+
hiccup/hiccup {:mvn/version "2.0.0"}
4343

4444
kirasystems/aging-session {:mvn/version "0.5.0"
4545
:exclusions [org.clojure/clojurescript]}

src/clojars/repo_indexing.clj

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[clojars.retry :as retry]
55
[clojars.s3 :as s3]
66
[clojars.web.common :as common]
7-
[clojars.web.safe-hiccup :as safe-hiccup]
87
[clojure.java.io :as io]
98
[clojure.string :as str]
109
[hiccup.element :as el])
@@ -64,24 +63,24 @@
6463
(defn- generate-index
6564
^String
6665
[path entries]
67-
(safe-hiccup/html5
68-
{:lang "en"}
69-
[:head
70-
[:meta {:charset "utf-8"}]
71-
[:meta {:name "viewport" :content "width=device-width,initial-scale=1"}]
72-
[:title (format "Clojars Repository: %s" (or path "/"))]]
73-
[:body
74-
[:header
75-
[:h1 (or path "/")]]
76-
[:hr]
77-
[:main
78-
[:pre#contents
79-
(when (some? path)
80-
(list
81-
(el/link-to "../" "../")
82-
"\n"))
83-
(mapcat entry-line entries)]]
84-
[:hr]]))
66+
(str (common/html5
67+
{:lang "en"}
68+
[:head
69+
[:meta {:charset "utf-8"}]
70+
[:meta {:name "viewport" :content "width=device-width,initial-scale=1"}]
71+
[:title (format "Clojars Repository: %s" (or path "/"))]]
72+
[:body
73+
[:header
74+
[:h1 (or path "/")]]
75+
[:hr]
76+
[:main
77+
[:pre#contents
78+
(when (some? path)
79+
(list
80+
(el/link-to "../" "../")
81+
"\n"))
82+
(mapcat entry-line entries)]]
83+
[:hr]])))
8584

8685
(defn- sort-entries
8786
[entries]

src/clojars/web.clj

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
[clojars.friend.oauth.github :as github]
1010
[clojars.friend.oauth.gitlab :as gitlab]
1111
[clojars.friend.registration :as registration]
12-
[clojars.http-utils :refer [wrap-secure-session wrap-additional-security-headers]]
12+
[clojars.http-utils :refer [wrap-additional-security-headers
13+
wrap-secure-session]]
1314
[clojars.log :as log]
1415
[clojars.middleware :refer [wrap-ignore-trailing-slash]]
1516
[clojars.routes.api :as api]
@@ -22,9 +23,8 @@
2223
[clojars.routes.user :as user]
2324
[clojars.routes.verify :as verify]
2425
[clojars.web.browse :refer [browse]]
25-
[clojars.web.common :as common :refer [html-doc]]
26+
[clojars.web.common :as common :refer [html-doc raw]]
2627
[clojars.web.dashboard :refer [dashboard index-page]]
27-
[clojars.web.safe-hiccup :refer [raw]]
2828
[clojars.web.search :as search]
2929
[clojure.java.io :as io]
3030
[compojure.core :refer [ANY context GET PUT routes]]
@@ -55,30 +55,30 @@
5555
(let [db (:spec db)]
5656
(routes
5757
(GET "/" _
58-
(try-account
59-
#(if %
60-
(dashboard db %)
61-
(index-page db stats %))))
58+
(try-account
59+
#(if %
60+
(dashboard db %)
61+
(index-page db stats %))))
6262
(GET "/search" {:keys [params]}
63-
(try-account
64-
#(let [validated-params (-> params
65-
(update :page try-parse-page))]
66-
(search/search search % validated-params))))
63+
(try-account
64+
#(let [validated-params (-> params
65+
(update :page try-parse-page))]
66+
(search/search search % validated-params))))
6767
(GET "/projects" {:keys [params]}
68-
(try-account
69-
#(let [validated-params
70-
(-> params
71-
(update :from (partial common/check-no-null-bytes "from"))
72-
(update :page try-parse-page))]
73-
(browse db % validated-params))))
68+
(try-account
69+
#(let [validated-params
70+
(-> params
71+
(update :from (partial common/check-no-null-bytes "from"))
72+
(update :page try-parse-page))]
73+
(browse db % validated-params))))
7474
(GET "/security" []
75-
(try-account
76-
#(html-doc "Security" {:account %}
77-
(raw (slurp (io/resource "security.html"))))))
75+
(try-account
76+
#(html-doc "Security" {:account %}
77+
(raw (slurp (io/resource "security.html"))))))
7878
(GET "/dmca" []
79-
(try-account
80-
#(html-doc "DMCA" {:account %}
81-
(raw (slurp (io/resource "dmca.html"))))))
79+
(try-account
80+
#(html-doc "DMCA" {:account %}
81+
(raw (slurp (io/resource "dmca.html"))))))
8282
session/routes
8383
(group/routes db event-emitter)
8484
(artifact/routes db stats)
@@ -90,12 +90,12 @@
9090
(api/routes db stats)
9191
(PUT "*" _ {:status 405 :headers {} :body "Did you mean to use /repo?"})
9292
(ANY "*" _
93-
(try-account
94-
#(not-found
95-
(html-doc "Page not found" {:account %}
96-
[:div.small-section
97-
[:h1 "Page not found"]
98-
[:p "Thundering typhoons! I think we lost it. Sorry!"]])))))))
93+
(try-account
94+
#(not-found
95+
(html-doc "Page not found" {:account %}
96+
[:div.small-section
97+
[:h1 "Page not found"]
98+
[:p "Thundering typhoons! I think we lost it. Sorry!"]])))))))
9999

100100
(def ^:private defaults-config
101101
(-> ring-defaults/secure-site-defaults
@@ -149,19 +149,19 @@
149149
(let [db (:spec db)]
150150
(routes
151151
(-> (context
152-
"/repo" _
153-
(-> (repo/routes storage db event-emitter search)
154-
(friend/authenticate
155-
{:credential-fn (auth/token-credential-fn db)
156-
:workflows [(workflows/http-basic :realm "clojars")]
157-
:allow-anon? false
158-
:unauthenticated-handler
159-
(partial workflows/http-basic-deny "clojars")})
160-
(repo/wrap-reject-non-token db)
161-
(repo/wrap-exceptions error-reporter)
162-
(repo/wrap-file (:repo (config)))
163-
(log/wrap-request-context)
164-
(repo/wrap-reject-double-dot)))
152+
"/repo" _
153+
(-> (repo/routes storage db event-emitter search)
154+
(friend/authenticate
155+
{:credential-fn (auth/token-credential-fn db)
156+
:workflows [(workflows/http-basic :realm "clojars")]
157+
:allow-anon? false
158+
:unauthenticated-handler
159+
(partial workflows/http-basic-deny "clojars")})
160+
(repo/wrap-reject-non-token db)
161+
(repo/wrap-exceptions error-reporter)
162+
(repo/wrap-file (:repo (config)))
163+
(log/wrap-request-context)
164+
(repo/wrap-reject-double-dot)))
165165
(wrap-secure-session))
166166
(-> (token-breach/routes db event-emitter)
167167
(wrap-exceptions error-reporter)

0 commit comments

Comments
 (0)