diff --git a/app/assets/javascripts/projects/index.js b/app/assets/javascripts/projects/index.js index ea2a340b1..08b116154 100644 --- a/app/assets/javascripts/projects/index.js +++ b/app/assets/javascripts/projects/index.js @@ -476,7 +476,7 @@ var ProjectsIndex = (function() { data: { ...requestParams, ...{ page: 1 } }, success: function(data) { $('#breadcrumbsWrapper').html(data.breadcrumbs_html); - $(projectsWrapper).find('.projects-title').text(data.title); + $(projectsWrapper).find('.projects-title').html(data.title_html); $(toolbarWrapper).html(data.toolbar_html); viewContainer.data('projects-cards-url', data.projects_cards_url); viewContainer.removeClass('no-results'); diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index 301420503..5f1819ec0 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -296,11 +296,11 @@ class ExperimentsController < ApplicationController .select(:id, :name, :color) tags = tags.map do |tag| - { value: tag.id, label: sanitize_input(tag.name), params: { color: sanitize_input(tag.color) } } + { value: tag.id, label: escape_input(tag.name), params: { color: escape_input(tag.color) } } end if params[:query].present? && tags.select { |tag| tag[:label] == params[:query] }.blank? - tags << { value: 0, label: sanitize_input(params[:query]), params: { color: nil } } + tags << { value: 0, label: escape_input(params[:query]), params: { color: nil } } end render json: tags end @@ -358,12 +358,12 @@ class ExperimentsController < ApplicationController @experiment.workflowimg.purge render json: { message: t('experiments.table.modal_move_modules.success_flash', - experiment: sanitize_input(dst_experiment.name)) } + experiment: escape_input(dst_experiment.name)) } rescue StandardError => e Rails.logger.error(e.message) Rails.logger.error(e.backtrace.join("\n")) render json: { - message: t('experiments.table.modal_move_modules.error_flash', experiment: sanitize_input(dst_experiment.name)) + message: t('experiments.table.modal_move_modules.error_flash', experiment: escape_input(dst_experiment.name)) }, status: :unprocessable_entity raise ActiveRecord::Rollback end @@ -444,7 +444,7 @@ class ExperimentsController < ApplicationController def assigned_users_to_tasks users = current_team.users.where(id: @experiment.my_modules.joins(:user_my_modules).select(:user_id)) .search(false, params[:query]).map do |u| - { value: u.id, label: sanitize_input(u.name), params: { avatar_url: avatar_path(u, :icon_small) } } + { value: u.id, label: escape_input(u.name), params: { avatar_url: avatar_path(u, :icon_small) } } end render json: users, status: :ok diff --git a/app/controllers/my_module_tags_controller.rb b/app/controllers/my_module_tags_controller.rb index 0235505d5..e880b4bed 100644 --- a/app/controllers/my_module_tags_controller.rb +++ b/app/controllers/my_module_tags_controller.rb @@ -120,11 +120,11 @@ class MyModuleTagsController < ApplicationController .limit(6) tags = tags.map do |tag| - { value: tag.id, label: sanitize_input(tag.name), params: { color: sanitize_input(tag.color) } } + { value: tag.id, label: escape_input(tag.name), params: { color: escape_input(tag.color) } } end if params[:query].present? && tags.select { |tag| tag[:label] == params[:query] }.blank? - tags << { value: 0, label: sanitize_input(params[:query]), params: { color: nil } } + tags << { value: 0, label: escape_input(params[:query]), params: { color: nil } } end render json: tags diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 9d9372e2b..a4586b5be 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -51,15 +51,15 @@ class ProjectsController < ApplicationController breadcrumbs_html = render_to_string(partial: 'projects/index/breadcrumbs.html.erb', locals: { target_folder: current_folder, folder_page: true }) projects_cards_url = project_folder_cards_url(current_folder) - title = if @inline_editable_title_config.present? - render_to_string(partial: 'shared/inline_editing', - locals: { - initial_value: current_folder&.name, - config: @inline_editable_title_config - }) - else - current_folder.name - end + title_html = if @inline_editable_title_config.present? + render_to_string(partial: 'shared/inline_editing', + locals: { + initial_value: current_folder&.name, + config: @inline_editable_title_config + }) + else + escape_input(current_folder.name) + end else breadcrumbs_html = '' projects_cards_url = cards_projects_url @@ -71,7 +71,7 @@ class ProjectsController < ApplicationController render json: { projects_cards_url: projects_cards_url, breadcrumbs_html: breadcrumbs_html, - title: title, + title_html: title_html, next_page: cards.next_page, toolbar_html: render_to_string(partial: 'projects/index/toolbar.html.erb'), cards_html: render_to_string( @@ -347,7 +347,7 @@ class ProjectsController < ApplicationController def users_filter users = current_team.users.search(false, params[:query]).map do |u| - { value: u.id, label: sanitize_input(u.name), params: { avatar_url: avatar_path(u, :icon_small) } } + { value: u.id, label: escape_input(u.name), params: { avatar_url: avatar_path(u, :icon_small) } } end render json: users, status: :ok diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 97ce37c15..4cef8c8d8 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -696,18 +696,18 @@ class ProtocolsController < ApplicationController @db_json = {} @toolong = false @db_json['name'] = pio_eval_title_len( - sanitize_input(not_null(params['protocol']['name'])) + escape_input(not_null(params['protocol']['name'])) ) # since scinote only has description field, and protocols.io has many others # ,here i am putting everything important from protocols.io into description @db_json['authors'] = pio_eval_title_len( - sanitize_input(not_null(params['protocol']['authors'])) + escape_input(not_null(params['protocol']['authors'])) ) @db_json['created_at'] = pio_eval_title_len( - sanitize_input(not_null(params['protocol']['created_at'])) + escape_input(not_null(params['protocol']['created_at'])) ) @db_json['updated_at'] = pio_eval_title_len( - sanitize_input(not_null(params['protocol']['last_modified'])) + escape_input(not_null(params['protocol']['last_modified'])) ) @db_json['steps'] = {} diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index e68ec7dfd..796c4f07d 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -131,10 +131,8 @@ class RepositoriesController < ApplicationController if @repository.save log_activity(:create_inventory) - flash[:success] = t('repositories.index.modal_create.success_flash', - name: @repository.name) - render json: { url: repository_path(@repository) }, - status: :ok + flash[:success] = t('repositories.index.modal_create.success_flash_html', name: @repository.name) + render json: { url: repository_path(@repository) } else render json: @repository.errors, status: :unprocessable_entity @@ -455,7 +453,10 @@ class RepositoriesController < ApplicationController item_id: @repository.id, field_to_udpate: 'name', path_to_update: team_repository_path(@repository), - label_after: "#{sanitized_kw}" end diff --git a/app/datatables/report_datatable.rb b/app/datatables/report_datatable.rb index c4ef21891..74f061134 100644 --- a/app/datatables/report_datatable.rb +++ b/app/datatables/report_datatable.rb @@ -56,13 +56,13 @@ class ReportDatatable < CustomDatatable records.map do |record| { '0' => record.id, - '1' => sanitize_input(record.project_name), - '2' => sanitize_input(record.name), - '3' => sanitize_input(record.code), + '1' => escape_input(record.project_name), + '2' => escape_input(record.name), + '3' => escape_input(record.code), '4' => pdf_file(record), '5' => docx_file(record), - '6' => sanitize_input(record.created_by_name), - '7' => sanitize_input(record.modified_by_name), + '6' => escape_input(record.created_by_name), + '7' => escape_input(record.modified_by_name), '8' => I18n.l(record.created_at, format: :full), '9' => I18n.l(record.updated_at, format: :full), 'archived' => record.project.archived?, diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 039c1720a..2789e1c84 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -159,16 +159,16 @@ module ApplicationHelper
" + label_after: + sanitize_input( + " " + ) } end diff --git a/app/controllers/user_my_modules_controller.rb b/app/controllers/user_my_modules_controller.rb index 37125a1c1..f77e94f5d 100644 --- a/app/controllers/user_my_modules_controller.rb +++ b/app/controllers/user_my_modules_controller.rb @@ -134,7 +134,7 @@ class UserMyModulesController < ApplicationController user_hash = { value: user.id, - label: sanitize_input(user.full_name), + label: escape_input(user.full_name), params: { avatar_url: avatar_path(user, :icon_small), designated: user.designated, diff --git a/app/datatables/label_template_datatable.rb b/app/datatables/label_template_datatable.rb index d050ff686..da9928ce0 100644 --- a/app/datatables/label_template_datatable.rb +++ b/app/datatables/label_template_datatable.rb @@ -36,11 +36,11 @@ class LabelTemplateDatatable < CustomDatatable '0' => record.id, '1' => record.default, '2' => append_format_icon(record), - '3' => sanitize_input(record.label_format), - '4' => sanitize_input(record.description), - '5' => sanitize_input(record.modified_by), + '3' => escape_input(record.label_format), + '4' => escape_input(record.description), + '5' => escape_input(record.modified_by), '6' => I18n.l(record.updated_at, format: :full), - '7' => sanitize_input(record.created_by_user), + '7' => escape_input(record.created_by_user), '8' => I18n.l(record.created_at, format: :full), 'recordInfoUrl' => '', 'DT_RowAttr': { @@ -60,7 +60,7 @@ class LabelTemplateDatatable < CustomDatatable "label_template_icons/#{record.icon}.svg", class: 'label-template-icon' ), - name: sanitize_input(record.name) + name: escape_input(record.name) } end diff --git a/app/datatables/protocols_datatable.rb b/app/datatables/protocols_datatable.rb index fbfebab74..55d22629c 100644 --- a/app/datatables/protocols_datatable.rb +++ b/app/datatables/protocols_datatable.rb @@ -185,7 +185,7 @@ class ProtocolsDatatable < CustomDatatable kws = record.protocol_keywords_str.split(", ") res = [] kws.sort_by{ |word| word.downcase }.each do |kw| - sanitized_kw = sanitize_input(kw) + sanitized_kw = escape_input(kw) res << "#{sanitize_input(user.email)}
) +#{escape_input(user.email)}
) if user_still_in_team user_team_assignment = user.user_assignments.find_by(assignable: team) user_description += %(#{I18n.t('atwho.users.popover_html', - role: sanitize_input(user_team_assignment.user_role.name.capitalize), - team: sanitize_input(user_team_assignment.assignable.name), + role: escape_input(user_team_assignment.user_role.name.capitalize), + team: escape_input(user_team_assignment.assignable.name), time: I18n.l(user_team_assignment.created_at, format: :full_date))}