Skip to content

Commit 9c700a3

Browse files
authored
Merge from docusealco/wip
2 parents 6008265 + 89bf83f commit 9c700a3

29 files changed

Lines changed: 374 additions & 143 deletions

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Install Ruby
1313
uses: ruby/setup-ruby@v1
1414
with:
15-
ruby-version: 4.0.1
15+
ruby-version: 4.0.5
1616
- name: Cache gems
1717
uses: actions/cache@v4
1818
with:
@@ -37,7 +37,7 @@ jobs:
3737
- name: Install Ruby
3838
uses: ruby/setup-ruby@v1
3939
with:
40-
ruby-version: 4.0.1
40+
ruby-version: 4.0.5
4141
- name: Cache gems
4242
uses: actions/cache@v4
4343
with:
@@ -89,7 +89,7 @@ jobs:
8989
- name: Install Ruby
9090
uses: ruby/setup-ruby@v1
9191
with:
92-
ruby-version: 4.0.1
92+
ruby-version: 4.0.5
9393
- name: Cache gems
9494
uses: actions/cache@v4
9595
with:
@@ -132,7 +132,7 @@ jobs:
132132
- name: Install Ruby
133133
uses: ruby/setup-ruby@v1
134134
with:
135-
ruby-version: 4.0.1
135+
ruby-version: 4.0.5
136136
- name: Set up Node
137137
uses: actions/setup-node@v1
138138
with:
@@ -163,7 +163,7 @@ jobs:
163163
yarn install
164164
sudo apt-get update
165165
sudo apt-get install -y libvips
166-
wget -O pdfium-linux.tgz "https://github.com/docusealco/pdfium-binaries/releases/latest/download/pdfium-linux-$(uname -m | sed 's/x86_64/x64/;s/aarch64/arm64/').tgz"
166+
wget -O pdfium-linux.tgz "https://github.com/bblanchon/pdfium-binaries/releases/latest/download/pdfium-linux-$(uname -m | sed 's/x86_64/x64/;s/aarch64/arm64/').tgz"
167167
sudo tar -xzf pdfium-linux.tgz --strip-components=1 -C /usr/lib lib/libpdfium.so
168168
rm -f pdfium-linux.tgz
169169
- name: Run

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ruby:4.0.1-alpine AS download
1+
FROM ruby:4.0.5-alpine AS download
22

33
WORKDIR /fonts
44

@@ -13,7 +13,7 @@ RUN apk --no-cache add wget && \
1313
mkdir -p /pdfium-linux && \
1414
tar -xzf pdfium-linux.tgz -C /pdfium-linux
1515

16-
FROM ruby:4.0.1-alpine AS webpack
16+
FROM ruby:4.0.5-alpine AS webpack
1717

1818
ENV RAILS_ENV=production
1919
ENV NODE_ENV=production
@@ -40,15 +40,15 @@ COPY ./app/views ./app/views
4040

4141
RUN echo "gem 'shakapacker'" > Gemfile && ./bin/shakapacker
4242

43-
FROM ruby:4.0.1-alpine AS app
43+
FROM ruby:4.0.5-alpine AS app
4444

4545
ENV RAILS_ENV=production
4646
ENV BUNDLE_WITHOUT="development:test"
4747
ENV OPENSSL_CONF=/etc/openssl_legacy.cnf
4848

4949
WORKDIR /app
5050

51-
RUN apk add --no-cache libpq vips redis vips-heif onnxruntime
51+
RUN apk add --no-cache libpq vips redis onnxruntime
5252

5353
RUN addgroup -g 2000 docuseal && adduser -u 2000 -G docuseal -s /bin/sh -D -h /home/docuseal docuseal
5454

@@ -94,6 +94,7 @@ WORKDIR /data/docuseal
9494
ENV HOME=/home/docuseal
9595
ENV WORKDIR=/data/docuseal
9696
ENV VIPS_MAX_COORD=17000
97+
ENV VIPS_BLOCK_UNTRUSTED=1
9798

9899
EXPOSE 3000
99100
CMD ["/app/bin/bundle", "exec", "puma", "-C", "/app/config/puma.rb", "--dir", "/app"]

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source 'https://rubygems.org'
44

5-
ruby '4.0.1'
5+
ruby '4.0.5'
66

77
gem 'addressable'
88
gem 'arabic-letter-connector', require: false

Gemfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ GEM
195195
railties (>= 6.1.0)
196196
faker (3.6.1)
197197
i18n (>= 1.8.11, < 2)
198-
faraday (2.14.1)
198+
faraday (2.14.2)
199199
faraday-net_http (>= 2.0, < 3.5)
200200
json
201201
logger
@@ -275,7 +275,7 @@ GEM
275275
reline (>= 0.4.2)
276276
jmespath (1.6.2)
277277
json (2.19.5)
278-
jwt (3.1.2)
278+
jwt (3.2.0)
279279
base64
280280
language_server-protocol (3.17.0.5)
281281
launchy (3.1.1)
@@ -662,7 +662,7 @@ DEPENDENCIES
662662
webmock
663663

664664
RUBY VERSION
665-
ruby 4.0.1
665+
ruby 4.0.5
666666

667667
BUNDLED WITH
668668
4.0.3

app/controllers/api/active_storage_blobs_proxy_controller.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class ActiveStorageBlobsProxyController < ApiBaseController
99

1010
before_action :set_cors_headers
1111
before_action :set_noindex_headers
12+
before_action :set_security_headers
1213

14+
# rubocop:disable Metrics
1315
def show
1416
blob_uuid, purp, exp = ApplicationRecord.signed_id_verifier.verified(params[:signed_uuid])
1517

@@ -21,6 +23,12 @@ def show
2123

2224
blob = ActiveStorage::Blob.find_by!(uuid: blob_uuid)
2325

26+
if Submitters::DANGEROUS_EXTENSIONS.include?(blob.filename.extension.to_s.downcase)
27+
Rollbar.error('Dangerous extension') if defined?(Rollbar)
28+
29+
return head :unprocessable_content
30+
end
31+
2432
attachment = blob.attachments.take
2533

2634
@record = attachment.record
@@ -45,6 +53,7 @@ def show
4553
end
4654
end
4755
end
56+
# rubocop:enable Metrics
4857

4958
private
5059

app/controllers/api/active_storage_blobs_proxy_legacy_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class ActiveStorageBlobsProxyLegacyController < ApiBaseController
99

1010
before_action :set_cors_headers
1111
before_action :set_noindex_headers
12+
before_action :set_security_headers
1213

1314
# rubocop:disable Metrics
1415
def show
@@ -18,6 +19,12 @@ def show
1819

1920
return head :not_found unless blob
2021

22+
if Submitters::DANGEROUS_EXTENSIONS.include?(blob.filename.extension.to_s.downcase)
23+
Rollbar.error('Dangerous extension') if defined?(Rollbar)
24+
25+
return head :unprocessable_content
26+
end
27+
2128
is_permitted = blob.attachments.any? do |a|
2229
(current_user && a.record.account.id == current_user.account_id) ||
2330
a.record.account.account_configs.any? { |e| e.key == 'legacy_blob_proxy' } ||

app/controllers/api/api_base_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ def set_noindex_headers
102102
headers['X-Robots-Tag'] = 'noindex'
103103
end
104104

105+
def set_security_headers
106+
response.headers['X-Content-Type-Options'] = 'nosniff'
107+
end
108+
105109
def set_cors_headers
106110
headers['Access-Control-Allow-Origin'] = '*'
107111
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, PATCH, DELETE, OPTIONS'

app/controllers/api/attachments_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ def create
1616
return render json: { error: I18n.t('form_has_been_archived') }, status: :unprocessable_content
1717
end
1818

19+
file = params[:file]
20+
1921
if params[:type].in?(%w[initials signature])
20-
image = Vips::Image.new_from_file(params[:file].path)
22+
image = ImageUtils.load_vips(file.read, content_type: file.content_type)
2123

2224
if ImageUtils.blank?(image)
2325
Rollbar.error("Empty signature: #{@submitter.id}") if defined?(Rollbar)
@@ -33,7 +35,7 @@ def create
3335
end
3436
end
3537

36-
attachment = Submitters.create_attachment!(@submitter, params)
38+
attachment = Submitters.create_attachment!(@submitter, file)
3739

3840
if params[:remember_signature] == 'true' && @submitter.email.present?
3941
cookies.encrypted[:signature_uuids] = build_new_cookie_signatures_json(@submitter, attachment)

app/controllers/user_initials_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ def update
1111

1212
return redirect_to settings_profile_index_path, notice: I18n.t('unable_to_save_initials') if file.blank?
1313

14+
extension = File.extname(file.original_filename).delete_prefix('.').downcase
15+
16+
if Submitters::DANGEROUS_EXTENSIONS.include?(extension)
17+
raise Submitters::MaliciousFileExtension, "File type '.#{extension}' is not allowed."
18+
end
19+
1420
blob = ActiveStorage::Blob.create_and_upload!(io: file.open,
1521
filename: file.original_filename,
1622
content_type: file.content_type)

app/controllers/user_signatures_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ def update
1111

1212
return redirect_to settings_profile_index_path, notice: I18n.t('unable_to_save_signature') if file.blank?
1313

14+
extension = File.extname(file.original_filename).delete_prefix('.').downcase
15+
16+
if Submitters::DANGEROUS_EXTENSIONS.include?(extension)
17+
raise Submitters::MaliciousFileExtension, "File type '.#{extension}' is not allowed."
18+
end
19+
1420
blob = ActiveStorage::Blob.create_and_upload!(io: file.open,
1521
filename: file.original_filename,
1622
content_type: file.content_type)

0 commit comments

Comments
 (0)