Skip to content

Commit

Permalink
[Automated] Merged master into target k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
va-vsp-bot authored Apr 10, 2024
2 parents 1e60dd7 + 1e32812 commit 323c04f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions app/models/form_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FormAttachment < ApplicationRecord

def set_file_data!(file, file_password = nil)
attachment_uploader = get_attachment_uploader
file = unlock_pdf(file, file_password) if file_password.present?
file = unlock_pdf(file, file_password) if File.extname(file).downcase == '.pdf' && file_password.present?
attachment_uploader.store!(file)
self.file_data = { filename: attachment_uploader.filename }.to_json
rescue CarrierWave::IntegrityError => e
Expand All @@ -36,15 +36,13 @@ def get_file
private

def unlock_pdf(file, file_password)
return file unless File.extname(file) == '.pdf'

pdftk = PdfForms.new(Settings.binaries.pdftk)
tmpf = Tempfile.new(['decrypted_form_attachment', '.pdf'])

begin
pdftk.call_pdftk(file.tempfile.path, 'input_pw', file_password, 'output', tmpf.path)
rescue PdfForms::PdftkError => e
file_regex = %r{/(?:\w+/)*[\w-]+\.pdf\b}
file_regex = %r{/(?:\w+/)*[\w-]+\.pdf\b}i
password_regex = /(input_pw).*?(output)/
sanitized_message = e.message.gsub(file_regex, '[FILTERED FILENAME]').gsub(password_regex, '\1 [FILTERED] \2')
log_message_to_sentry(sanitized_message, 'warn')
Expand Down
2 changes: 1 addition & 1 deletion spec/models/form_attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

describe '#unlock_pdf' do
let(:file_name) { 'locked_pdf_password_is_test.pdf' }
let(:file_name) { 'locked_pdf_password_is_test.Pdf' }
let(:bad_password) { 'bad_pw' }

context 'when provided password is incorrect' do
Expand Down

0 comments on commit 323c04f

Please sign in to comment.