Fix WOPI proof verification [SCI-12096] (#8637)

This commit is contained in:
Alex Kriuchykhin 2025-07-07 14:15:22 +02:00 committed by GitHub
parent 35dbfa5d17
commit 62c48ccf33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 25 deletions

View file

@ -358,6 +358,7 @@ class Asset < ApplicationRecord
end
def put_wopi_contents(new_file)
new_file.rewind
if file_size.zero? && version.zero?
# wopi client puts initial blanc file therefore skipping version creation
file.attach(io: new_file, filename: file_name)

View file

@ -10,19 +10,20 @@ module VersionedAttachments
define_method :"attach_#{name}_version" do |*args, **options|
ActiveRecord::Base.transaction(requires_new: true) do
__send__(:"previous_#{name.to_s.pluralize}").attach([__send__(name).blob.signed_id]) if __send__(name).attached?
__send__(:"previous_#{name.to_s.pluralize}").attach(__send__(name).blob) if __send__(name).attached?
__send__(name).attach(*args, **options)
new_blob = __send__(name).blob
new_blob.metadata['created_by_id'] ||= last_modified_by_id
metadata = new_blob.metadata
metadata['created_by_id'] ||= last_modified_by_id
# set version of current latest file if previous versions exist
new_blob.save! and next unless __send__(:"previous_#{name.to_s.pluralize}").any?
if __send__(:"previous_#{name.to_s.pluralize}").any?
new_version = (__send__(:"previous_#{name.to_s.pluralize}").last.blob.metadata['version'] || 1) + 1
metadata['version'] = new_version
end
new_version =
(__send__(:"previous_#{name.to_s.pluralize}").last.blob.metadata['version'] || 1) + 1
new_blob.metadata['version'] = new_version
new_blob.save!
new_blob.persisted? ? new_blob.update_column(:metadata, metadata) : new_blob.metadata = metadata
end
end

View file

@ -30,10 +30,10 @@ module WopiUtil
# with this discovery public key (two key possible old/new)
def wopi_verify_proof(token, timestamp, signed_proof, signed_proof_old, url)
discovery = current_wopi_discovery
token_length = [token.length].pack('>N').bytes
timestamp_bytes = [timestamp.to_i].pack('>Q').bytes.reverse
timestamp_length = [timestamp_bytes.length].pack('>N').bytes
url_length = [url.length].pack('>N').bytes
token_length = [token.length].pack('N').bytes
timestamp_bytes = [timestamp.to_i].pack('Q').bytes.reverse
timestamp_length = [timestamp_bytes.length].pack('N').bytes
url_length = [url.length].pack('N').bytes
expected_proof = token_length + token.bytes +
url_length + url.upcase.bytes +

View file

@ -3,7 +3,6 @@
require 'active_storage/previewer/libreoffice_previewer'
require 'active_storage/analyzer/image_analyzer/custom_image_magick'
require 'active_storage/analyzer/text_extraction_analyzer'
require 'active_storage/downloader'
# Enable PDF previews for files
Rails.application.config.x.enable_pdf_previews = ENV['ACTIVESTORAGE_ENABLE_PDF_PREVIEWS'] == 'true'
@ -18,16 +17,3 @@ Rails.application.config.active_storage.variable_content_types << 'image/svg+xml
Rails.application.config.active_storage.variant_processor = :vips if ENV['ACTIVESTORAGE_ENABLE_VIPS'] == 'true'
ActiveStorage::Downloader.class_eval do
def open(key, checksum: nil, verify: true, name: 'ActiveStorage-', tmpdir: nil)
open_tempfile(name, tmpdir) do |file|
download key, file
if checksum == 'dummy' || checksum.nil?
ActiveStorage::Blob.find_by(key: key).update(checksum: Digest::MD5.file(file).base64digest)
else
verify_integrity_of(file, checksum: checksum) if verify
end
yield file
end
end
end