Skip to content

Commit 1818ac3

Browse files
committed
1680: add sanitation of error-message from potentially external account_link partner
1 parent 0f59bfc commit 1818ac3

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

app/services/task_service/push_external.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ def execute
1212
body = @zip.string
1313
begin
1414
response = connection.post {|request| request_parameters(request, body) }
15-
if response.success?
16-
nil
17-
else
18-
response.status == 401 ? I18n.t('tasks.export_external_confirm.not_authorized', account_link: @account_link.name) : response.body
19-
end
15+
return nil if response.success?
16+
return I18n.t('tasks.export_external_confirm.not_authorized', account_link: @account_link.name) if response.status == 401
17+
18+
ERB::Util.html_escape(response.body)
2019
rescue StandardError => e
2120
e
2221
end

config/locales/de/controllers/tasks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ de:
77
duplicate:
88
error_alert: Die Aufgabe konnte nicht dupliziert werden.
99
export_external_confirm:
10-
error: 'Der Export der Aufgabe (%{title}) ist fehlgeschlagen. <br> Fehler: %{error}'
10+
error: 'Der Export der Aufgabe (%{title}) ist fehlgeschlagen. <br><br> Fehler: %{error}'
1111
not_authorized: Die Autorisierung mit "%{account_link}" konnte nicht hergestellt werden. Ist der API-Schlüssel korrekt?
1212
success: Aufgabe (%{title}) erfolgreich exportiert.
1313
import:

config/locales/en/controllers/tasks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ en:
77
duplicate:
88
error_alert: Task could not be duplicated
99
export_external_confirm:
10-
error: 'Export of task (%{title}) failed. <br> Error: %{error}'
10+
error: 'Export of task (%{title}) failed. <br><br> Error: %{error}'
1111
not_authorized: Authorization with could not be established with "%{account_link}". Is the API Key correct?
1212
success: Task (%{title}) successfully exported.
1313
import:

spec/services/task_service/push_external_spec.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@
5151
let(:status) { 500 }
5252
let(:response) { 'an error occured' }
5353

54-
it { is_expected.to be response }
54+
it { is_expected.to eql response }
55+
56+
context 'when response contains problematic characters' do
57+
let(:response) { 'an <error> occurred' }
58+
59+
it { is_expected.to eql 'an &lt;error&gt; occurred' }
60+
end
5561
end
5662

5763
context 'when response status is 401' do

0 commit comments

Comments
 (0)