Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
57c2af4f
Commit
57c2af4f
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Security: add HTTP headers to prevent browsers from caching responses #662
parent
8992908e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/core.clj
+1
-1
1 addition, 1 deletion
src/metabase/core.clj
src/metabase/middleware/format.clj
+10
-0
10 additions, 0 deletions
src/metabase/middleware/format.clj
src/metabase/middleware/log_api_call.clj
+1
-1
1 addition, 1 deletion
src/metabase/middleware/log_api_call.clj
with
12 additions
and
2 deletions
src/metabase/core.clj
+
1
−
1
View file @
57c2af4f
...
...
@@ -46,11 +46,11 @@
(
s/replace
#
"/$"
""
))
; strip off trailing slash if one was included
(
-site-url
(
or
origin
host
))))
(
def
app
"The primary entry point to the HTTP server"
(
->
routes/routes
(
log-api-call
:request
:response
)
add-security-headers
; [METABASE] Add HTTP headers to API responses to prevent them from being cached
format-response
; [METABASE] Do formatting before converting to JSON so serializer doesn't barf
(
wrap-json-body
; extracts json POST body and makes it avaliable on request
{
:keywords?
true
})
...
...
This diff is collapsed.
Click to expand it.
src/metabase/middleware/format.clj
+
10
−
0
View file @
57c2af4f
...
...
@@ -3,6 +3,7 @@
(
cheshire
factory
[
generate
:refer
[
add-encoder
encode-str
]])
[
medley.core
:refer
[
filter-vals
map-vals
]]
[
metabase.middleware.log-api-call
:refer
[
api-call?
]]
[
metabase.models.interface
:refer
[
api-serialize
]]
[
metabase.util
:as
util
]))
...
...
@@ -32,6 +33,15 @@
(
add-encoder
java.sql.Date
(
fn
[
^
java.sql.Date
date
^
com.fasterxml.jackson.core.JsonGenerator
json-generator
]
(
.writeString
json-generator
(
.toString
date
))))
(
defn
add-security-headers
"Add HTTP headers to tell browsers not to cache API responses."
[
handler
]
(
fn
[
request
]
(
let
[
response
(
handler
request
)]
(
update
response
:headers
merge
(
when
(
api-call?
request
)
{
"Cache-Control"
"max-age=0, no-cache, must-revalidate, proxy-revalidate"
"Expires"
"Tue, 03 Jul 2001 06:00:00 GMT"
; rando date in the past
"Last-Modified"
"{now} GMT"
})))))
;; ## FORMAT RESPONSE MIDDLEWARE
(
defn
format-response
...
...
This diff is collapsed.
Click to expand it.
src/metabase/middleware/log_api_call.clj
+
1
−
1
View file @
57c2af4f
...
...
@@ -50,7 +50,7 @@
(
log-response
request
response
elapsed-time
))
response
))))))
(
defn
-
api-call?
(
defn
api-call?
"Is this ring request an API call (does path start with `/api`)?"
[{
:keys
[
^
String
uri
]}]
(
and
(
>=
(
count
uri
)
4
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment