trek 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AGENTS.md +12 -11
- data/CHANGELOG.md +51 -0
- data/Gemfile.lock +124 -126
- data/Makefile +7 -1
- data/README.md +17 -21
- data/app/components/trek/form/content_editor_component/content_editor_component.css +4 -8
- data/app/components/trek/form/image_field_component/image_field_component.js +1 -2
- data/app/components/trek/form/password_strength_component/password_strength_component.css +2 -0
- data/app/components/trek/form/sound_field_component/sound_field_component.js +1 -2
- data/app/components/trek/security_check_component/security_check_component.css +69 -0
- data/app/components/trek/security_check_component/security_check_component.html.slim +19 -0
- data/app/components/trek/security_check_component/security_check_component.js +15 -0
- data/app/components/trek/security_check_component.rb +19 -0
- data/app/content/trek/content/cleaner.rb +1 -1
- data/app/content/trek/content/list_item.rb +1 -1
- data/app/content/trek/content/paragraph.rb +7 -2
- data/app/controllers/concerns/trek/auditable.rb +5 -2
- data/app/controllers/concerns/trek/localization.rb +6 -2
- data/app/jobs/trek/purge_expired_sign_in_codes_job.rb +15 -0
- data/app/policies/trek/security_check_policy.rb +8 -0
- data/app/uploaders/image_uploader.rb +77 -15
- data/config/locales/trek.en.yml +71 -0
- data/config/locales/trek.fr.yml +71 -0
- data/docs/.vitepress/config.mjs +1 -0
- data/docs/background-jobs.md +10 -5
- data/docs/deploy.md +69 -6
- data/docs/getting-started.md +15 -17
- data/docs/index.md +1 -1
- data/docs/personal-data.md +61 -0
- data/docs/proxies.md +2 -2
- data/docs/reference/components.md +2 -2
- data/docs/reference/concerns/fragmentable.md +12 -6
- data/docs/reference/concerns/orderable.md +2 -2
- data/docs/reference/concerns/search-engine-optimizable.md +1 -1
- data/docs/reference/concerns/searchable.md +14 -1
- data/docs/reference/concerns/sectionable.md +7 -3
- data/docs/reference/concerns/versionable.md +1 -1
- data/docs/reference/controllers.md +33 -1
- data/docs/reference/environment-variables.md +2 -2
- data/docs/reference/formatters.md +2 -1
- data/docs/reference/forms.md +6 -3
- data/docs/reference/generators/admin-user.md +1 -1
- data/docs/reference/generators/audit-log.md +12 -13
- data/docs/reference/generators/install.md +20 -9
- data/docs/reference/generators/public-accounts.md +21 -3
- data/docs/reference/generators/scaffold.md +28 -9
- data/docs/reference/generators/security-headers.md +4 -3
- data/docs/reference/generators/taxonomies.md +1 -1
- data/docs/reference/icons.md +5 -3
- data/docs/reference/index.md +10 -8
- data/docs/reference/models/current.md +5 -3
- data/docs/reference/models/page-version.md +1 -1
- data/docs/reference/models/user.md +5 -8
- data/docs/reference/uploaders.md +25 -0
- data/docs/reference/validators.md +1 -1
- data/docs/security.md +30 -9
- data/docs/what-is-trek.md +3 -3
- data/lib/generators/trek/USAGE +1 -1
- data/lib/generators/trek/audit_log_generator.rb +8 -0
- data/lib/generators/trek/helpers.rb +17 -0
- data/lib/generators/trek/install/admin/routes_generator.rb +2 -1
- data/lib/generators/trek/install/admin/security_check_generator.rb +36 -0
- data/lib/generators/trek/install/ci_generator.rb +19 -0
- data/lib/generators/trek/install/postcss_generator.rb +1 -2
- data/lib/generators/trek/install/translations_generator.rb +1 -2
- data/lib/generators/trek/install_generator.rb +8 -7
- data/lib/generators/trek/public_accounts_generator.rb +34 -7
- data/lib/generators/trek/scaffold_generator.rb +22 -21
- data/lib/generators/trek/scalingo_generator.rb +13 -1
- data/lib/generators/trek/templates/.gitlab-ci.yml +10 -1
- data/lib/generators/trek/templates/AGENTS.md +2 -2
- data/lib/generators/trek/templates/Makefile +1 -0
- data/lib/generators/trek/templates/config/i18n-tasks.yml.erb +0 -8
- data/lib/generators/trek/templates/controllers/admin/security_checks_controller.rb +11 -0
- data/lib/generators/trek/templates/controllers/concerns/trek/authentication.rb +13 -4
- data/lib/generators/trek/templates/initializers/good_job.rb.tt +7 -5
- data/lib/generators/trek/templates/layouts/admin.html.slim +5 -0
- data/lib/generators/trek/templates/policies/security_check.rb +4 -0
- data/lib/generators/trek/templates/public_accounts/api/controllers/sessions_controller.rb.tt +13 -1
- data/lib/generators/trek/templates/public_accounts/api/controllers/sign_in_codes_controller.rb.tt +5 -0
- data/lib/generators/trek/templates/public_accounts/jobs/sign_in_code_job.rb.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/locales/accounts.en.yml.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/locales/accounts.fr.yml.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/models/account.rb.tt +16 -2
- data/lib/generators/trek/templates/public_accounts/spec/api/sign_ins_spec.rb.tt +30 -0
- data/lib/generators/trek/templates/public_accounts/spec/models/account/sign_in_code_spec.rb.tt +10 -0
- data/lib/generators/trek/templates/public_accounts/spec/models/account_spec.rb.tt +21 -1
- data/lib/generators/trek/templates/public_accounts/spec/web/sign_ins_spec.rb.tt +22 -0
- data/lib/generators/trek/templates/public_accounts/web/authentication.rb.tt +1 -1
- data/lib/generators/trek/templates/public_accounts/web/controllers/sessions_controller.rb.tt +8 -1
- data/lib/generators/trek/templates/public_accounts/web/controllers/sign_in_codes_controller.rb.tt +5 -0
- data/lib/generators/trek/templates/public_accounts/web/views/password_resets/edit.html.slim.tt +4 -1
- data/lib/generators/trek/templates/public_accounts/web/views/passwords/edit.html.slim.tt +4 -1
- data/lib/generators/trek/templates/public_accounts/web/views/registrations/new.html.slim.tt +3 -1
- data/lib/generators/trek/templates/public_accounts/web/views/sessions/new.html.slim.tt +3 -1
- data/lib/generators/trek/templates/spec/requests/admin/pages_spec.rb +11 -0
- data/lib/generators/trek/templates/spec/requests/admin/security_checks_spec.rb +24 -0
- data/lib/generators/trek/templates/spec/requests/admin/sign_in_notices_spec.rb +33 -0
- data/lib/generators/trek/templates/views/admin/pages/_form.html.slim +1 -1
- data/lib/generators/trek/templates/views/admin/security_checks/show.html.slim +9 -0
- data/lib/generators/trek/templates/views/admin/user_password_resets/edit.html.slim +6 -1
- data/lib/generators/trek/templates/views/admin/user_sessions/new.html.slim +4 -1
- data/lib/tasks/trek/attachments.rake +12 -0
- data/lib/tasks/trek/security.rake +10 -0
- data/lib/trek/disposable_email_domains.rb +9 -20
- data/lib/trek/engine.rb +5 -0
- data/lib/trek/json_compatibility.rb +20 -0
- data/lib/trek/security_check.rb +241 -0
- data/lib/trek/stored_image_metadata.rb +88 -0
- data/lib/trek/version.rb +1 -1
- data/lib/trek.rb +2 -1
- data/package.json +5 -6
- data/postcss.config.js +0 -3
- data/trek.gemspec +5 -6
- data/yarn.lock +983 -1042
- metadata +33 -31
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Trek
|
|
4
|
+
# Checks a running app's configuration against what docs/security.md recommends, for
|
|
5
|
+
# `bin/rails trek:security:check`: each check gives a status, a message and the docs page to read.
|
|
6
|
+
#
|
|
7
|
+
# check = Trek::SecurityCheck.new
|
|
8
|
+
# check.results.each { |result| puts result.status, result.message }
|
|
9
|
+
# check.failed? # any :failure
|
|
10
|
+
#
|
|
11
|
+
# Run it where the app runs in production, with its configuration and database (the admin accounts
|
|
12
|
+
# are counted). Given the request of an admin page (`request:`), it also checks what only a request
|
|
13
|
+
# tells: that it came over HTTPS, and the address Rails sees behind a CDN.
|
|
14
|
+
class SecurityCheck
|
|
15
|
+
# :ok, :info (a fact, nothing to fix), :warning (a recommendation not followed), :failure (a
|
|
16
|
+
# setting Trek relies on)
|
|
17
|
+
STATUSES = %i[ok info warning failure].freeze
|
|
18
|
+
|
|
19
|
+
Result = Data.define(:check, :status, :message, :docs) do
|
|
20
|
+
STATUSES.each { |status| define_method(:"#{status}?") { self.status == status } }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
DOCS = "https://trek.etamin.studio"
|
|
24
|
+
# Admins who haven't signed in for longer are reported as dormant
|
|
25
|
+
DORMANT_AFTER = 6.months
|
|
26
|
+
|
|
27
|
+
CHECKS = %i[https content_security_policy cache_store trusted_proxies admin_allowed_ips audit_log
|
|
28
|
+
session_purge cron admins encryption].freeze
|
|
29
|
+
REQUEST_CHECKS = %i[request_https remote_ip].freeze
|
|
30
|
+
|
|
31
|
+
# The headers CDNs put the visitor's address in (Cloudflare, Akamai and Cloudflare Enterprise, Fastly)
|
|
32
|
+
CDN_IP_HEADERS = %w[HTTP_CF_CONNECTING_IP HTTP_TRUE_CLIENT_IP HTTP_FASTLY_CLIENT_IP].freeze
|
|
33
|
+
|
|
34
|
+
def initialize(app = Rails.application, user_class: "User", env: ENV, request: nil)
|
|
35
|
+
@app = app
|
|
36
|
+
@user_class = user_class
|
|
37
|
+
@env = env
|
|
38
|
+
@request = request
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def results
|
|
42
|
+
@results ||= [*(REQUEST_CHECKS if @request), *CHECKS].flat_map { |check| send(check) }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def failed?
|
|
46
|
+
results.any?(&:failure?)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
SYMBOLS = { ok: "✓", info: "•", warning: "⚠", failure: "✗" }.freeze
|
|
50
|
+
|
|
51
|
+
# The report the rake task prints, dated, to keep as evidence of the check
|
|
52
|
+
def to_text(time: Time.current)
|
|
53
|
+
header = I18n.t("trek.security_check.header", app: @app.class.module_parent_name, environment: Rails.env,
|
|
54
|
+
time: time.utc.iso8601, trek: Trek::VERSION, rails: Rails.version, ruby: RUBY_VERSION)
|
|
55
|
+
lines = results.map { |result| "#{SYMBOLS.fetch(result.status)} #{result.message}\n #{result.docs}" }
|
|
56
|
+
counts = STATUSES.index_with { |status| results.count { |result| result.status == status } }
|
|
57
|
+
[header, *lines, I18n.t("trek.security_check.summary", **counts)].join("\n\n") + "\n"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
62
|
+
def config = @app.config
|
|
63
|
+
|
|
64
|
+
def https
|
|
65
|
+
return result(:https, :failure, :off, docs: "/reference/generators/security-headers#hsts") unless config.force_ssl
|
|
66
|
+
|
|
67
|
+
hsts = config.ssl_options.fetch(:hsts, {})
|
|
68
|
+
return result(:https, :warning, :no_hsts, docs: "/reference/generators/security-headers#hsts") if hsts == false
|
|
69
|
+
|
|
70
|
+
expires = (hsts.is_a?(Hash) && hsts[:expires]) || ActionDispatch::SSL.default_hsts_options[:expires]
|
|
71
|
+
result(:https, :ok, :on, duration: duration(expires), docs: "/reference/generators/security-headers#hsts")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def request_https
|
|
75
|
+
docs = "/proxies#how-rails-finds-the-address"
|
|
76
|
+
return result(:request_https, :ok, :https, docs:) if @request.ssl?
|
|
77
|
+
|
|
78
|
+
result(:request_https, :failure, :http, docs:)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Behind a CDN missing from trusted_proxies, Rails takes the CDN for the visitor: its own header
|
|
82
|
+
# then names someone else than request.remote_ip
|
|
83
|
+
def remote_ip
|
|
84
|
+
docs = "/proxies#behind-a-cdn-or-a-web-application-firewall"
|
|
85
|
+
ip = @request.remote_ip
|
|
86
|
+
forwarded = CDN_IP_HEADERS.filter_map { |header| @request.headers[header].presence }.first
|
|
87
|
+
return result(:remote_ip, :failure, :cdn, ip:, forwarded:, docs:) if forwarded && forwarded != ip
|
|
88
|
+
|
|
89
|
+
result(:remote_ip, :info, :seen, ip:, docs:)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def content_security_policy
|
|
93
|
+
docs = "/reference/generators/security-headers#report-first-then-enforce"
|
|
94
|
+
return result(:content_security_policy, :failure, :none, docs:) unless config.content_security_policy
|
|
95
|
+
return result(:content_security_policy, :warning, :report_only, docs:) if config.content_security_policy_report_only
|
|
96
|
+
|
|
97
|
+
result(:content_security_policy, :ok, :enforced, docs:)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# The sign-in limits count in the cache: a store each process keeps to itself splits the count
|
|
101
|
+
def cache_store
|
|
102
|
+
store = Rails.cache
|
|
103
|
+
docs = "/reference/models/user#failed-sign-ins"
|
|
104
|
+
case store
|
|
105
|
+
when ActiveSupport::Cache::NullStore, ActiveSupport::Cache::MemoryStore
|
|
106
|
+
result(:cache_store, :failure, :per_process, store: store.class.name, docs:)
|
|
107
|
+
when ActiveSupport::Cache::FileStore
|
|
108
|
+
result(:cache_store, :warning, :per_server, store: store.class.name, docs:)
|
|
109
|
+
else
|
|
110
|
+
result(:cache_store, :ok, :shared, store: store.class.name, docs:)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def trusted_proxies
|
|
115
|
+
proxies = config.action_dispatch.trusted_proxies
|
|
116
|
+
docs = "/proxies#behind-a-cdn-or-a-web-application-firewall"
|
|
117
|
+
return result(:trusted_proxies, :info, :default, docs:) if proxies.nil?
|
|
118
|
+
|
|
119
|
+
result(:trusted_proxies, :info, :set, count: Array(proxies).size, docs:)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def admin_allowed_ips
|
|
123
|
+
allowed = @env["ADMIN_ALLOWED_IPS"].to_s.split(/[\s,]+/).compact_blank
|
|
124
|
+
docs = "/proxies#restricting-the-admin-to-ip-addresses"
|
|
125
|
+
return result(:admin_allowed_ips, :info, :unset, docs:) if allowed.empty?
|
|
126
|
+
|
|
127
|
+
result(:admin_allowed_ips, :ok, :set, count: allowed.size, docs:)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def audit_log
|
|
131
|
+
docs = "/reference/generators/audit-log"
|
|
132
|
+
return result(:audit_log, :warning, :not_installed, docs:) unless audit_log_installed?
|
|
133
|
+
|
|
134
|
+
purge_docs = "/reference/generators/audit-log#purging-old-rows"
|
|
135
|
+
return result(:audit_log, :info, :purge_unknown, docs: purge_docs) unless good_job?
|
|
136
|
+
return result(:audit_log, :ok, :purged, docs: purge_docs) if scheduled?("Trek::AuditLog::PurgeJob")
|
|
137
|
+
|
|
138
|
+
result(:audit_log, :failure, :not_purged, docs: purge_docs)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def session_purge
|
|
142
|
+
docs = "/reference/models/user#sessions"
|
|
143
|
+
return result(:session_purge, :info, :unknown, docs:) unless good_job?
|
|
144
|
+
return result(:session_purge, :ok, :scheduled, docs:) if scheduled?("Trek::PurgeExpiredSessionsJob")
|
|
145
|
+
|
|
146
|
+
result(:session_purge, :warning, :not_scheduled, docs:)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def cron
|
|
150
|
+
docs = "/background-jobs#scheduled-jobs-cron"
|
|
151
|
+
return result(:cron, :info, :other_backend, adapter: queue_adapter, docs:) unless good_job?
|
|
152
|
+
return result(:cron, :ok, :enabled, docs:) if config.good_job.enable_cron
|
|
153
|
+
|
|
154
|
+
result(:cron, :failure, :disabled, docs:)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def admins
|
|
158
|
+
users = @user_class.safe_constantize
|
|
159
|
+
return [] unless users
|
|
160
|
+
|
|
161
|
+
privileged = users.where(role: Trek::Users::Roles::PRIVILEGED_ROLES)
|
|
162
|
+
# In one query: two counts of the same shape are an N+1 for Prosopite, which host apps run in their specs
|
|
163
|
+
by_role = privileged.group(:role).count
|
|
164
|
+
docs = "/reference/models/user#roles"
|
|
165
|
+
[
|
|
166
|
+
result(:admins, :info, :count, admins: by_role.fetch("admin", 0), privileged: by_role.values.sum, docs:),
|
|
167
|
+
passkeys(users, privileged),
|
|
168
|
+
dormant(users, privileged),
|
|
169
|
+
password_expiry(users)
|
|
170
|
+
].compact
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def passkeys(users, privileged)
|
|
174
|
+
return unless users.reflect_on_association(:passkeys) && users.connection.table_exists?(users.reflect_on_association(:passkeys).table_name)
|
|
175
|
+
|
|
176
|
+
count = privileged.where.missing(:passkeys).count
|
|
177
|
+
docs = "/reference/models/user#passkeys"
|
|
178
|
+
return result(:passkeys, :ok, :all, docs:) if count.zero?
|
|
179
|
+
|
|
180
|
+
result(:passkeys, :warning, :password_only, count:, docs:)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# By their latest sign-in (current_sign_in_at: last_sign_in_at is the one before), or since their
|
|
184
|
+
# account was created when they never signed in, so a user invited last week isn't dormant
|
|
185
|
+
def dormant(users, privileged)
|
|
186
|
+
return unless users.column_names.include?("current_sign_in_at")
|
|
187
|
+
|
|
188
|
+
since = DORMANT_AFTER.ago
|
|
189
|
+
count = privileged.where(current_sign_in_at: ...since)
|
|
190
|
+
.or(privileged.where(current_sign_in_at: nil, created_at: ...since)).count
|
|
191
|
+
docs = "/reference/models/user#sign-ins"
|
|
192
|
+
return result(:dormant, :ok, :none, duration: duration(DORMANT_AFTER), docs:) if count.zero?
|
|
193
|
+
|
|
194
|
+
result(:dormant, :warning, :some, count:, duration: duration(DORMANT_AFTER), docs:)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def password_expiry(users)
|
|
198
|
+
return unless users.respond_to?(:password_expires_after)
|
|
199
|
+
|
|
200
|
+
docs = "/reference/models/user#expiry-and-renewal"
|
|
201
|
+
return result(:password_expiry, :info, :never, docs:) unless users.password_expires_after
|
|
202
|
+
|
|
203
|
+
result(:password_expiry, :ok, :after, duration: duration(users.password_expires_after), docs:)
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def encryption
|
|
207
|
+
ActiveRecord::Encryption.config.primary_key
|
|
208
|
+
result(:encryption, :ok, :configured, docs: "/security#cryptography")
|
|
209
|
+
rescue ActiveRecord::Encryption::Errors::Configuration
|
|
210
|
+
result(:encryption, :warning, :not_configured, docs: "/security#cryptography")
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def audit_log_installed?
|
|
214
|
+
defined?(::AuditLog) && ::AuditLog.table_exists?
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def good_job?
|
|
218
|
+
queue_adapter.to_s == "good_job"
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
def queue_adapter
|
|
222
|
+
adapter = config.active_job.queue_adapter
|
|
223
|
+
adapter.is_a?(Symbol) || adapter.is_a?(String) ? adapter : ActiveJob::Base.queue_adapter_name
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
# Whether GoodJob's cron runs the job, whatever the entry's name
|
|
227
|
+
def scheduled?(job_class)
|
|
228
|
+
return false unless config.respond_to?(:good_job) && config.good_job.cron
|
|
229
|
+
|
|
230
|
+
config.good_job.cron.values.any? { |entry| entry[:class].to_s == job_class }
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def duration(seconds)
|
|
234
|
+
ActionController::Base.helpers.distance_of_time_in_words(0, seconds.to_i)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def result(check, status, key, docs:, **values)
|
|
238
|
+
Result.new(check:, status:, message: I18n.t("trek.security_check.#{check}.#{key}", **values), docs: DOCS + docs)
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
module Trek
|
|
2
|
+
# Strips the metadata (EXIF, with the GPS location and the camera's serial number, XMP, IPTC) of
|
|
3
|
+
# the images stored before ImageUploader stripped it on upload, as it does now. Each file is
|
|
4
|
+
# replaced in place, under the same id, so that every reference to it keeps working: records,
|
|
5
|
+
# page versions, the content editor's image blocks, and files no record references anymore but
|
|
6
|
+
# still published.
|
|
7
|
+
#
|
|
8
|
+
# Goes through the files of a storage (S3, the file system, or in memory): the images by their
|
|
9
|
+
# extension, and the sizes the derivation endpoint stored under derivatives/, which have none.
|
|
10
|
+
class StoredImageMetadata
|
|
11
|
+
Entry = Struct.new(:id, :status, keyword_init: true)
|
|
12
|
+
|
|
13
|
+
IMAGE_ID = %r{\.(jpe?g|png|webp)\z|\Aderivatives/}i
|
|
14
|
+
METADATA_FIELD = /\A(exif|xmp|iptc)-/
|
|
15
|
+
|
|
16
|
+
def initialize(storage = Shrine.storages[:store], uploader: ImageUploader)
|
|
17
|
+
@storage = storage
|
|
18
|
+
@uploader = uploader
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Yields an Entry per image carrying metadata, whose status is :stripped, :strippable (dry
|
|
22
|
+
# run) or :failed (libvips couldn't read or write it, e.g. a truncated file).
|
|
23
|
+
def strip(dry_run: false)
|
|
24
|
+
return enum_for(:strip, dry_run:) unless block_given?
|
|
25
|
+
|
|
26
|
+
# Apps have their own copy of ImageUploader, stripping only once updated
|
|
27
|
+
unless @uploader.private_method_defined?(:strip_metadata)
|
|
28
|
+
raise ArgumentError, "#{@uploader} doesn't strip metadata: update it first (bin/rails g trek:install:uploaders)"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
file_ids.each do |id|
|
|
32
|
+
next unless IMAGE_ID.match?(id)
|
|
33
|
+
|
|
34
|
+
status = strip_file(id, dry_run:)
|
|
35
|
+
yield Entry.new(id:, status:) if status
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def strip_file(id, dry_run:)
|
|
42
|
+
Shrine.with_file(@storage.open(id)) do |file|
|
|
43
|
+
mime_type = @uploader.determine_mime_type(file)
|
|
44
|
+
next unless @uploader::TYPES.include?(mime_type) && metadata?(file)
|
|
45
|
+
next :strippable if dry_run
|
|
46
|
+
|
|
47
|
+
replace(id, file, mime_type)
|
|
48
|
+
:stripped
|
|
49
|
+
end
|
|
50
|
+
rescue Vips::Error
|
|
51
|
+
:failed
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def metadata?(file)
|
|
55
|
+
Vips::Image.new_from_file(file.path).get_fields.any? { METADATA_FIELD.match?(it) }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Re-encoded as ImageUploader does on upload (its private method, so that both always match)
|
|
59
|
+
def replace(id, file, mime_type)
|
|
60
|
+
stripped = @uploader.new(:store).send(:strip_metadata, file, mime_type)
|
|
61
|
+
@storage.upload(stripped, id, **headers(id))
|
|
62
|
+
ensure
|
|
63
|
+
stripped&.close!
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# An S3 object's headers, which a new upload would otherwise lose (the Content-Type, and the
|
|
67
|
+
# Content-Disposition with the original file name)
|
|
68
|
+
def headers(id)
|
|
69
|
+
return {} unless @storage.respond_to?(:object)
|
|
70
|
+
|
|
71
|
+
object = @storage.object(id)
|
|
72
|
+
{ content_type: object.content_type, content_disposition: object.content_disposition,
|
|
73
|
+
cache_control: object.cache_control }.compact
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def file_ids
|
|
77
|
+
case @storage.class.name
|
|
78
|
+
when "Shrine::Storage::Memory" then @storage.store.keys
|
|
79
|
+
when "Shrine::Storage::FileSystem"
|
|
80
|
+
Dir.glob("**/*", base: @storage.directory.to_s).select { @storage.directory.join(it).file? }
|
|
81
|
+
when "Shrine::Storage::S3"
|
|
82
|
+
prefix = @storage.prefix && "#{@storage.prefix}/"
|
|
83
|
+
@storage.bucket.objects(**{ prefix: }.compact).lazy.map { it.key.delete_prefix(prefix.to_s) }
|
|
84
|
+
else raise ArgumentError, "#{@storage.class} can't list its files"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
data/lib/trek/version.rb
CHANGED
data/lib/trek.rb
CHANGED
|
@@ -4,7 +4,6 @@ require "action_policy"
|
|
|
4
4
|
require "acts_as_list"
|
|
5
5
|
require "blurhash"
|
|
6
6
|
require "closure_tree"
|
|
7
|
-
require "deepl"
|
|
8
7
|
require "dry-initializer"
|
|
9
8
|
require "email_validator"
|
|
10
9
|
require "fastimage"
|
|
@@ -34,9 +33,11 @@ module Trek
|
|
|
34
33
|
require_relative "trek/disposable_email_domains"
|
|
35
34
|
require_relative "trek/engine"
|
|
36
35
|
require_relative "trek/i18n_keys_resolver"
|
|
36
|
+
require_relative "trek/json_compatibility"
|
|
37
37
|
require_relative "trek/passkey_providers"
|
|
38
38
|
require_relative "trek/reverse_dns"
|
|
39
39
|
require_relative "trek/saved_attachments_reload"
|
|
40
|
+
require_relative "trek/stored_image_metadata"
|
|
40
41
|
require_relative "trek/typography_formatter"
|
|
41
42
|
require_relative "trek/version"
|
|
42
43
|
|
data/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trek",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "A modern content management & back-office system for Ruby on Rails",
|
|
5
5
|
"homepage": "https://trek.etamin.studio",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"@tiptap/extension-floating-menu": "^3.32.0",
|
|
30
30
|
"@tiptap/pm": "^3.32.0",
|
|
31
31
|
"@tiptap/starter-kit": "^3.32.0",
|
|
32
|
-
"@uppy/core": "^3.
|
|
33
|
-
"@uppy/locales": "^3.
|
|
34
|
-
"@uppy/thumbnail-generator": "^
|
|
35
|
-
"@uppy/xhr-upload": "^
|
|
32
|
+
"@uppy/core": "^6.3.1",
|
|
33
|
+
"@uppy/locales": "^5.3.2",
|
|
34
|
+
"@uppy/thumbnail-generator": "^6.0.1",
|
|
35
|
+
"@uppy/xhr-upload": "^6.0.1",
|
|
36
36
|
"hotkeys-js": "^3.13.15",
|
|
37
37
|
"normalize.css": "^8.0.1",
|
|
38
38
|
"slugify": "^1.6.6",
|
|
@@ -51,7 +51,6 @@
|
|
|
51
51
|
"postcss": "^8.4.30",
|
|
52
52
|
"postcss-flexbugs-fixes": "^5.0.2",
|
|
53
53
|
"postcss-import": "^15.1.0",
|
|
54
|
-
"postcss-inline-svg": "^5.0.0",
|
|
55
54
|
"postcss-modules": "^5.0.0",
|
|
56
55
|
"postcss-preset-env": "^7.8.3",
|
|
57
56
|
"prettier": "2.8.8",
|
data/postcss.config.js
CHANGED
data/trek.gemspec
CHANGED
|
@@ -33,23 +33,22 @@ Gem::Specification.new do |spec|
|
|
|
33
33
|
spec.add_dependency "aws-sdk-s3", "~> 1.117"
|
|
34
34
|
spec.add_dependency "blurhash", "~> 0.1"
|
|
35
35
|
spec.add_dependency "closure_tree", "~> 9.0"
|
|
36
|
-
spec.add_dependency "deepl-rb", "~> 3.0"
|
|
37
36
|
spec.add_dependency "dry-initializer", "~> 3.1"
|
|
38
37
|
spec.add_dependency "email_validator", "~> 2.2"
|
|
39
38
|
spec.add_dependency "fastimage", "~> 2.2"
|
|
40
39
|
spec.add_dependency "http_accept_language", "~> 2.1"
|
|
41
40
|
spec.add_dependency "i18n-tasks", "~> 1.0"
|
|
42
41
|
spec.add_dependency "image_processing", "~> 1.8"
|
|
43
|
-
# json 3's `JSON.parse` takes keyword options only, but ActiveSupport (up to 8.1.3.1) passes them
|
|
44
|
-
# positionally, which breaks `db/schema.rb` for jsonb columns with a default. Lift once Rails
|
|
45
|
-
# supports json 3 (spec/dummy/generated_files_spec.rb checks the schema dump).
|
|
46
|
-
spec.add_dependency "json", "< 3"
|
|
47
42
|
spec.add_dependency "kaminari"
|
|
48
43
|
spec.add_dependency "listen"
|
|
49
44
|
spec.add_dependency "lookbook", ">= 2.3.13"
|
|
50
45
|
spec.add_dependency "mobility", "~> 1.3.2"
|
|
51
46
|
spec.add_dependency "phonelib", "~> 0.8"
|
|
52
47
|
spec.add_dependency "postmark-rails"
|
|
48
|
+
# Not used by Trek: refract 1.1.0 (prosemirror → phlex → refract) refers to Prism::MissingNode,
|
|
49
|
+
# which Prism 2 removed, so an app eager loading it (in production, or on CI) fails at boot. Drop it
|
|
50
|
+
# once a refract release has https://github.com/yippee-fun/refract/pull/4 (requested in issue 6).
|
|
51
|
+
spec.add_dependency "prism", "< 2"
|
|
53
52
|
spec.add_dependency "prosemirror", ">= 1.0", "< 2"
|
|
54
53
|
spec.add_dependency "rails", [">= 8.0", "< 8.2"]
|
|
55
54
|
spec.add_dependency "rails-healthcheck"
|
|
@@ -60,7 +59,7 @@ Gem::Specification.new do |spec|
|
|
|
60
59
|
spec.add_dependency "strip_attributes", "~> 2.0"
|
|
61
60
|
spec.add_dependency "time_for_a_boolean", "~> 0.3"
|
|
62
61
|
spec.add_dependency "turbo-rails", ">= 1.0"
|
|
63
|
-
spec.add_dependency "valid_email2", "~> 7.
|
|
62
|
+
spec.add_dependency "valid_email2", "~> 7.2"
|
|
64
63
|
spec.add_dependency "view_component", "< 5.0"
|
|
65
64
|
spec.add_dependency "view_component-form", "~> 0.3"
|
|
66
65
|
spec.add_dependency "webauthn", "~> 3.4"
|