Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
877d8c9
build: remove unused pysch dependency
StephenHulme Apr 10, 2026
960f766
revert: restore deleted file - turns out it is used
StephenHulme Apr 10, 2026
604d5d6
fix: update usages of unsafe loading for controlled files
StephenHulme Apr 27, 2026
bfcc871
Merge branch 'develop' into sh51/remove-pysch-dependency
StephenHulme Apr 27, 2026
c40e26f
Merge branch 'develop' into sh51/remove-pysch-dependency
StephenHulme Apr 29, 2026
9892364
test: add descriptive context to bulk submission specs
StephenHulme Apr 29, 2026
2890168
fix: update YAML file loading functions
StephenHulme Apr 29, 2026
6f880c8
fix: allow the use of unsafe loading in Psych 4, same behaviour as in 3
StephenHulme Apr 29, 2026
f99987c
stlye: lint
StephenHulme Apr 29, 2026
aa5f96c
fix: allow symbol loading for accessioning tags
StephenHulme Apr 29, 2026
8e6f07e
fix: preview against latest record_loader beta version
StephenHulme Apr 30, 2026
b8ebbfe
fix: remove unrequired commas from asset_shapes
StephenHulme Apr 30, 2026
a28b173
security: be stricter in what files are unsafe_loaded
StephenHulme Apr 30, 2026
dcc7da5
fix: allow symbol loading for excel helpers
StephenHulme Apr 30, 2026
5f4d038
fix: allow aliases for excel helper
StephenHulme Apr 30, 2026
08fff5b
fix: allow HashWithIndifferentAccess loading for request options loading
StephenHulme Apr 30, 2026
a6b82fc
fix: allow request type serialization
StephenHulme Apr 30, 2026
ba92944
fix: allow additional request type serialization
StephenHulme Apr 30, 2026
6846d27
fix: allow primer programs serialization
StephenHulme Apr 30, 2026
544c06c
fix: allow broadcase_event serialization
StephenHulme Apr 30, 2026
c40fd04
fix: alllow loading of request options behaviour
StephenHulme Apr 30, 2026
7bb8f07
fix: allow tag_layout serialization
StephenHulme May 1, 2026
a6969d1
fix: allow Time for request options behaviour
StephenHulme May 1, 2026
aba4e20
security: allow HashWithIndifferentAccess to be loaded by default
StephenHulme May 5, 2026
26c9a5b
revert: add HashWithIndifferentAccess back to non-ActiveRecord loading
StephenHulme May 5, 2026
33481a0
fix: remove already-permitted HashWithIndifferentAccess
StephenHulme May 5, 2026
f61d322
fix: allow request options behaviour to load ActiveSupport::TimeZone
StephenHulme May 5, 2026
49b7688
fix: allow request options behaviour to load aliases
StephenHulme May 5, 2026
d462070
style: lint
StephenHulme May 5, 2026
582847e
style: update rubocop todo
StephenHulme May 5, 2026
adf8be8
Merge branch 'develop' into sh51/remove-pysch-dependency
StephenHulme May 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --no-exclude-limit`
# on 2026-04-22 15:46:09 UTC using RuboCop version 1.86.1.
# on 2026-05-05 14:43:06 UTC using RuboCop version 1.86.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -301,12 +301,11 @@ Lint/UselessOr:
- 'app/models/qcable/statemachine.rb'
- 'app/models/ui_helper/summary.rb'

# Offense count: 11
# Offense count: 7
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
Metrics/AbcSize:
Exclude:
- 'app/controllers/api/v2/transfers_controller.rb'
- 'app/controllers/studies/information_controller.rb'
- 'app/jobs/export_pool_xp_to_traction_job.rb'
- 'app/models/accession_service/base_service.rb'
- 'app/sample_manifest_excel/sample_manifest_excel/manifest_type_list.rb'
Expand Down Expand Up @@ -334,7 +333,7 @@ Metrics/CyclomaticComplexity:
- 'app/models/accession_service/base_service.rb'
- 'lib/limber/helper.rb'

# Offense count: 19
# Offense count: 18
# Configuration parameters: CountComments, Max, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Exclude:
Expand Down Expand Up @@ -617,7 +616,7 @@ RSpec/BeforeAfterAll:
- 'spec/sample_manifest_excel/worksheet_spec.rb'
- 'spec/sequencescape_excel/worksheet_spec.rb'

# Offense count: 342
# Offense count: 330
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Expand Down Expand Up @@ -649,7 +648,6 @@ RSpec/ContextWording:
- 'spec/models/barcode_spec.rb'
- 'spec/models/broadcast_event/lab_event_spec.rb'
- 'spec/models/broadcast_event/qc_assay_spec.rb'
- 'spec/models/bulk_submission_spec.rb'
- 'spec/models/comment_spec.rb'
- 'spec/models/illumina_htp/initial_stock_tube_purpose_spec.rb'
- 'spec/models/location_report_form_spec.rb'
Expand Down Expand Up @@ -840,7 +838,7 @@ RSpec/ExampleWording:
- 'spec/sequencescape_excel/validation_spec.rb'
- 'spec/sequencescape_excel/worksheet_spec.rb'

# Offense count: 27
# Offense count: 26
RSpec/ExpectInHook:
Exclude:
- 'spec/controllers/labwhere_receptions_controller_spec.rb'
Expand Down Expand Up @@ -1197,7 +1195,7 @@ RSpec/MultipleExpectations:
- 'spec/views/labware/show_chromium_chip_spec.rb'
- 'spec/views/samples/index_html_erb_spec.rb'

# Offense count: 243
# Offense count: 249
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
# SupportedStyles: always, named_only
RSpec/NamedSubject:
Expand Down
6 changes: 1 addition & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ group :default do
gem 'faraday-multipart'
gem 'rest-client' # Deprecated, but still used in some places, replace with Faraday where possible

# Fix incompatibility with between Ruby 3.1 and Psych 4 (used for yaml)
# see https://stackoverflow.com/a/71192990
gem 'psych', '< 4'

# State machine
gem 'aasm'
gem 'after_commit_everywhere', '~> 1.0' # Required by AASM
Expand All @@ -34,7 +30,7 @@ group :default do

# Provides bulk insert capabilities
gem 'activerecord-import'
gem 'record_loader', git: 'https://github.com/sanger/record_loader'
gem 'record_loader', git: 'https://github.com/sanger/record_loader', branch: 'sh51/psych-5'

gem 'mysql2', platforms: :mri
gem 'will_paginate'
Expand Down
12 changes: 8 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ GIT

GIT
remote: https://github.com/sanger/record_loader
revision: 9e7481f4d2342f042ab13465962e5d6689863198
revision: cbd59574d1090a0a81a770478a6b4042fa882f6a
branch: sh51/psych-5
specs:
record_loader (0.3.0)
record_loader (1.0.0)
psych (~> 5.0)

GIT
remote: https://github.com/sanger/sanger_barcode_format.git
Expand Down Expand Up @@ -377,7 +379,9 @@ GEM
pry (>= 0.13, < 0.17)
pry-rails (0.3.11)
pry (>= 0.13.0)
psych (3.3.4)
psych (5.3.1)
date
stringio
public_suffix (7.0.5)
puma (7.2.0)
nio4r (~> 2.0)
Expand Down Expand Up @@ -588,6 +592,7 @@ GEM
rbtree
set (~> 1.0)
ssrf_filter (1.2.0)
stringio (3.2.0)
syntax_tree (6.3.0)
prettier_print (>= 1.2.0)
syntax_tree-haml (4.0.3)
Expand Down Expand Up @@ -715,7 +720,6 @@ DEPENDENCIES
prettier_print
pry-byebug
pry-rails
psych (< 4)
puma
rack-acceptable
rack-cors
Expand Down
2 changes: 1 addition & 1 deletion app/models/broadcast_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BroadcastEvent < ApplicationRecord
# https://api.rubyonrails.org/classes/ActiveRecord/Inheritance/ClassMethods.html
validates :sti_type, presence: true

serialize :properties, coder: YAML
serialize :properties, coder: YAML, yaml: { permitted_classes: [ActionController::Parameters] }
self.inheritance_column = 'sti_type'

broadcast_with_warren
Expand Down
9 changes: 8 additions & 1 deletion app/models/request_type/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ def valid_options

belongs_to :request_type, optional: false
validates :request_option, :valid_options, presence: true
serialize :valid_options, coder: YAML
serialize :valid_options, coder: YAML, yaml: {
permitted_classes: [
Range,
RequestType::Validator::ArrayWithDefault,
RequestType::Validator::FlowcellTypeValidator,
RequestType::Validator::LibraryTypeValidator
]
}

delegate :include?, to: :valid_options

Expand Down
23 changes: 14 additions & 9 deletions app/models/submission/request_options_behaviour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ class HashWrapper
def self.load(hash_yaml)
return hash_yaml if hash_yaml.nil?

YAML.load(hash_yaml)
YAML.safe_load(hash_yaml,
aliases: true,
permitted_classes: [
ActiveSupport::HashWithIndifferentAccess,
ActiveSupport::TimeWithZone,
ActiveSupport::TimeZone,
Time
])
end

def self.dump(hash)
Expand All @@ -28,22 +35,20 @@ def request_options=(options)
super
end

private

def check_request_options
check_multipliers_are_valid
end
private :check_request_options

# rubocop:todo Metrics/PerceivedComplexity, Metrics/AbcSize
def check_multipliers_are_valid # rubocop:todo Metrics/CyclomaticComplexity
def check_multipliers_are_valid # rubocop:disable Metrics/CyclomaticComplexity
multipliers = request_options.try(:[], :multiplier)
return if multipliers.blank? # We're ok with nothing being specified!

# TODO[xxx]: should probably error if they've specified a request type that isn't being used
errors.add(:request_options, 'negative multiplier supplied') if multipliers.values.map(&:to_i).any?(&:negative?)
errors.add(:request_options, 'zero multiplier supplied') if multipliers.values.map(&:to_i).any?(&:zero?)
multiplier_values = multipliers.values.map(&:to_i)
errors.add(:request_options, 'negative multiplier supplied') if multiplier_values.any?(&:negative?)
errors.add(:request_options, 'zero multiplier supplied') if multiplier_values.any?(&:zero?)
false unless errors.empty?
end

# rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
private :check_multipliers_are_valid
end
3 changes: 2 additions & 1 deletion app/sequencescape_excel/sequencescape_excel/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module SequencescapeExcel
# Helpers
module Helpers
def load_file(folder, filename)
YAML.load_file(Rails.root.join(folder, "#{filename}.yml")).with_indifferent_access
file_path = Rails.root.join(folder, "#{filename}.yml")
YAML.safe_load_file(file_path, permitted_classes: [Symbol], aliases: true).with_indifferent_access
end
end
end
4 changes: 2 additions & 2 deletions config/default_records/asset_shapes/default_records.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ Fluidigm192:
sizes: [192]

StripTubeColumn:
horizontal_ratio: 1,
vertical_ratio: 8,
horizontal_ratio: 1
vertical_ratio: 8
description_strategy: Sequential
sizes: [8]

Expand Down
2 changes: 1 addition & 1 deletion config/initializers/accession.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
end

# add ena requirement fields here
ena_requirement_fields = YAML.load_file('config/ena_requirement_fields.yml')
ena_requirement_fields = YAML.safe_load_file('config/ena_requirement_fields.yml')
Rails.application.config.ena_requirement_fields = ena_requirement_fields.with_indifferent_access
2 changes: 1 addition & 1 deletion config/initializers/failure_reasons.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# frozen_string_literal: true
FAILURE_REASONS = YAML.load(File.open("#{Rails.root}/config/failure_reasons.yml"))
FAILURE_REASONS = YAML.safe_load_file("#{Rails.root}/config/failure_reasons.yml")
2 changes: 1 addition & 1 deletion config/initializers/flipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'yaml'
require 'flipper/adapters/active_record'

FLIPPER_FEATURES = YAML.load_file('./config/feature_flags.yml')
FLIPPER_FEATURES = YAML.safe_load_file('./config/feature_flags.yml')

Rails.application.configure do
## Memoization ensures that only one adapter call is made per feature per request.
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/phi_x.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

phi_x_config = YAML.load_file('config/phi_x.yml')
phi_x_config = YAML.safe_load_file('config/phi_x.yml')
Rails.application.config.phi_x = phi_x_config.with_indifferent_access
2 changes: 1 addition & 1 deletion config/initializers/process_locale_files_with_erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module I18n
module Backend
module Base
def load_yml(filename)
YAML.load(ERB.new(File.read(filename)).result)
YAML.unsafe_load(ERB.new(File.read(filename)).result)
end
end
end
Expand Down
20 changes: 2 additions & 18 deletions config/initializers/psych.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
# frozen_string_literal: true

Rails.application.configure do
# Fix for Psych::DisallowedClass: Tried to load unspecified class
config.active_record.yaml_column_permitted_classes =
Array(config.active_record.yaml_column_permitted_classes) +
%w[
Symbol
ActiveSupport::HashWithIndifferentAccess
ActiveSupport::TimeWithZone
ActiveSupport::TimeZone
HashWithIndifferentAccess
RequestType::Validator::ArrayWithDefault
RequestType::Validator::LibraryTypeValidator
RequestType::Validator::FlowcellTypeValidator
ActionController::Parameters
Set
Range
FieldInfo
Time
]
# Allow YAML columns to contain HashWithIndifferentAccess objects by default
ActiveRecord.yaml_column_permitted_classes += [ActiveSupport::HashWithIndifferentAccess]
end
2 changes: 1 addition & 1 deletion db/seeds/0001_snp_plate_purposes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
EOS

YAML
.load(plate_purposes)
.unsafe_load(plate_purposes)
.each do |plate_purpose|
attributes =
plate_purpose.reverse_merge(
Expand Down
3 changes: 2 additions & 1 deletion lib/accession.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module Accession
# @see ftp://ftp.sra.ebi.ac.uk/meta/xsd/ Schema definitions
module Helpers
def load_file(folder, filename)
YAML.load_file(Rails.root.join(folder, "#{filename}.yml")).with_indifferent_access
file_path = Rails.root.join(folder, "#{filename}.yml")
YAML.safe_load_file(file_path, permitted_classes: [Symbol]).with_indifferent_access
end
end

Expand Down
Loading
Loading