Skip to content

Commit 1f01fec

Browse files
Steffen Sieringph
Steffen Siering
authored andcommitted
Html escaping (#7445)
Add support to codecs and outputs to enable/disable escaping of html symbols in JSON strings. By default html escaping is enabled.
1 parent d1fbad9 commit 1f01fec

25 files changed

+363
-63
lines changed

CHANGELOG-developer.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The list below covers the major changes between 6.3.0 and master only.
2323
- Moving of TLS helper functions and structs from `output/tls` to `tlscommon`. {pull}7054[7054]
2424
- Port fields.yml collector to Golang {pull}6911[6911]
2525
- Dashboards under _meta/kibana are expected to be decoded. See https://github.com/elastic/beats/pull/7224 for a conversion script. {pull}7265[7265]
26+
- Constructor `(github.com/elastic/beats/libbeat/output/codec/json).New` expects a new `escapeHTML` parameter. {pull}7445[7445]
2627

2728
==== Bugfixes
2829

CHANGELOG.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ https://github.com/elastic/beats/compare/v6.2.3...master[Check the HEAD diff]
166166
- Add support for docker autodiscover to monitor containers on host network {pull}6708[6708]
167167
- Add ability to define input configuration as stringified JSON for autodiscover. {pull}7372[7372]
168168
- Add processor definition support for hints builder {pull}7386[7386]
169+
- Add support to disable html escaping in outputs. {pull}7445[7445]
169170

170171
*Auditbeat*
171172

auditbeat/auditbeat.reference.yml

+37-2
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ output.elasticsearch:
335335
# Set gzip compression level.
336336
#compression_level: 0
337337

338+
# Configure escaping html symbols in strings.
339+
#escape_html: true
340+
338341
# Optional protocol and basic auth credentials.
339342
#protocol: "https"
340343
#username: "elastic"
@@ -440,6 +443,9 @@ output.elasticsearch:
440443
# Set gzip compression level.
441444
#compression_level: 3
442445

446+
# Configure escaping html symbols in strings.
447+
#escape_html: true
448+
443449
# Optional maximum time to live for a connection to Logstash, after which the
444450
# connection will be re-established. A value of `0s` (the default) will
445451
# disable this feature.
@@ -554,6 +560,14 @@ output.elasticsearch:
554560
# Kafka version auditbeat is assumed to run against. Defaults to the "1.0.0".
555561
#version: '1.0.0'
556562

563+
# Configure JSON encoding
564+
#codec.json:
565+
# Pretty print json event
566+
#pretty: false
567+
568+
# Configure escaping html symbols in strings.
569+
#escape_html: true
570+
557571
# Metadata update configuration. Metadata do contain leader information
558572
# deciding which broker to use when publishing.
559573
#metadata:
@@ -656,6 +670,14 @@ output.elasticsearch:
656670
# Boolean flag to enable or disable the output module.
657671
#enabled: true
658672

673+
# Configure JSON encoding
674+
#codec.json:
675+
# Pretty print json event
676+
#pretty: false
677+
678+
# Configure escaping html symbols in strings.
679+
#escape_html: true
680+
659681
# The list of Redis servers to connect to. If load balancing is enabled, the
660682
# events are distributed to the servers in the list. If one server becomes
661683
# unreachable, the events are distributed to the reachable servers only.
@@ -757,6 +779,14 @@ output.elasticsearch:
757779
# Boolean flag to enable or disable the output module.
758780
#enabled: true
759781

782+
# Configure JSON encoding
783+
#codec.json:
784+
# Pretty print json event
785+
#pretty: false
786+
787+
# Configure escaping html symbols in strings.
788+
#escape_html: true
789+
760790
# Path to the directory where to save the generated files. The option is
761791
# mandatory.
762792
#path: "/tmp/auditbeat"
@@ -784,8 +814,13 @@ output.elasticsearch:
784814
# Boolean flag to enable or disable the output module.
785815
#enabled: true
786816

787-
# Pretty print json event
788-
#pretty: false
817+
# Configure JSON encoding
818+
#codec.json:
819+
# Pretty print json event
820+
#pretty: false
821+
822+
# Configure escaping html symbols in strings.
823+
#escape_html: true
789824

790825
#================================= Paths ======================================
791826

filebeat/filebeat.reference.yml

+37-2
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,9 @@ output.elasticsearch:
977977
# Set gzip compression level.
978978
#compression_level: 0
979979

980+
# Configure escaping html symbols in strings.
981+
#escape_html: true
982+
980983
# Optional protocol and basic auth credentials.
981984
#protocol: "https"
982985
#username: "elastic"
@@ -1082,6 +1085,9 @@ output.elasticsearch:
10821085
# Set gzip compression level.
10831086
#compression_level: 3
10841087

1088+
# Configure escaping html symbols in strings.
1089+
#escape_html: true
1090+
10851091
# Optional maximum time to live for a connection to Logstash, after which the
10861092
# connection will be re-established. A value of `0s` (the default) will
10871093
# disable this feature.
@@ -1196,6 +1202,14 @@ output.elasticsearch:
11961202
# Kafka version filebeat is assumed to run against. Defaults to the "1.0.0".
11971203
#version: '1.0.0'
11981204

1205+
# Configure JSON encoding
1206+
#codec.json:
1207+
# Pretty print json event
1208+
#pretty: false
1209+
1210+
# Configure escaping html symbols in strings.
1211+
#escape_html: true
1212+
11991213
# Metadata update configuration. Metadata do contain leader information
12001214
# deciding which broker to use when publishing.
12011215
#metadata:
@@ -1298,6 +1312,14 @@ output.elasticsearch:
12981312
# Boolean flag to enable or disable the output module.
12991313
#enabled: true
13001314

1315+
# Configure JSON encoding
1316+
#codec.json:
1317+
# Pretty print json event
1318+
#pretty: false
1319+
1320+
# Configure escaping html symbols in strings.
1321+
#escape_html: true
1322+
13011323
# The list of Redis servers to connect to. If load balancing is enabled, the
13021324
# events are distributed to the servers in the list. If one server becomes
13031325
# unreachable, the events are distributed to the reachable servers only.
@@ -1399,6 +1421,14 @@ output.elasticsearch:
13991421
# Boolean flag to enable or disable the output module.
14001422
#enabled: true
14011423

1424+
# Configure JSON encoding
1425+
#codec.json:
1426+
# Pretty print json event
1427+
#pretty: false
1428+
1429+
# Configure escaping html symbols in strings.
1430+
#escape_html: true
1431+
14021432
# Path to the directory where to save the generated files. The option is
14031433
# mandatory.
14041434
#path: "/tmp/filebeat"
@@ -1426,8 +1456,13 @@ output.elasticsearch:
14261456
# Boolean flag to enable or disable the output module.
14271457
#enabled: true
14281458

1429-
# Pretty print json event
1430-
#pretty: false
1459+
# Configure JSON encoding
1460+
#codec.json:
1461+
# Pretty print json event
1462+
#pretty: false
1463+
1464+
# Configure escaping html symbols in strings.
1465+
#escape_html: true
14311466

14321467
#================================= Paths ======================================
14331468

heartbeat/heartbeat.reference.yml

+37-2
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ output.elasticsearch:
444444
# Set gzip compression level.
445445
#compression_level: 0
446446

447+
# Configure escaping html symbols in strings.
448+
#escape_html: true
449+
447450
# Optional protocol and basic auth credentials.
448451
#protocol: "https"
449452
#username: "elastic"
@@ -549,6 +552,9 @@ output.elasticsearch:
549552
# Set gzip compression level.
550553
#compression_level: 3
551554

555+
# Configure escaping html symbols in strings.
556+
#escape_html: true
557+
552558
# Optional maximum time to live for a connection to Logstash, after which the
553559
# connection will be re-established. A value of `0s` (the default) will
554560
# disable this feature.
@@ -663,6 +669,14 @@ output.elasticsearch:
663669
# Kafka version heartbeat is assumed to run against. Defaults to the "1.0.0".
664670
#version: '1.0.0'
665671

672+
# Configure JSON encoding
673+
#codec.json:
674+
# Pretty print json event
675+
#pretty: false
676+
677+
# Configure escaping html symbols in strings.
678+
#escape_html: true
679+
666680
# Metadata update configuration. Metadata do contain leader information
667681
# deciding which broker to use when publishing.
668682
#metadata:
@@ -765,6 +779,14 @@ output.elasticsearch:
765779
# Boolean flag to enable or disable the output module.
766780
#enabled: true
767781

782+
# Configure JSON encoding
783+
#codec.json:
784+
# Pretty print json event
785+
#pretty: false
786+
787+
# Configure escaping html symbols in strings.
788+
#escape_html: true
789+
768790
# The list of Redis servers to connect to. If load balancing is enabled, the
769791
# events are distributed to the servers in the list. If one server becomes
770792
# unreachable, the events are distributed to the reachable servers only.
@@ -866,6 +888,14 @@ output.elasticsearch:
866888
# Boolean flag to enable or disable the output module.
867889
#enabled: true
868890

891+
# Configure JSON encoding
892+
#codec.json:
893+
# Pretty print json event
894+
#pretty: false
895+
896+
# Configure escaping html symbols in strings.
897+
#escape_html: true
898+
869899
# Path to the directory where to save the generated files. The option is
870900
# mandatory.
871901
#path: "/tmp/heartbeat"
@@ -893,8 +923,13 @@ output.elasticsearch:
893923
# Boolean flag to enable or disable the output module.
894924
#enabled: true
895925

896-
# Pretty print json event
897-
#pretty: false
926+
# Configure JSON encoding
927+
#codec.json:
928+
# Pretty print json event
929+
#pretty: false
930+
931+
# Configure escaping html symbols in strings.
932+
#escape_html: true
898933

899934
#================================= Paths ======================================
900935

libbeat/_meta/config.reference.yml

+37-2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ output.elasticsearch:
230230
# Set gzip compression level.
231231
#compression_level: 0
232232

233+
# Configure escaping html symbols in strings.
234+
#escape_html: true
235+
233236
# Optional protocol and basic auth credentials.
234237
#protocol: "https"
235238
#username: "elastic"
@@ -335,6 +338,9 @@ output.elasticsearch:
335338
# Set gzip compression level.
336339
#compression_level: 3
337340

341+
# Configure escaping html symbols in strings.
342+
#escape_html: true
343+
338344
# Optional maximum time to live for a connection to Logstash, after which the
339345
# connection will be re-established. A value of `0s` (the default) will
340346
# disable this feature.
@@ -449,6 +455,14 @@ output.elasticsearch:
449455
# Kafka version beatname is assumed to run against. Defaults to the "1.0.0".
450456
#version: '1.0.0'
451457

458+
# Configure JSON encoding
459+
#codec.json:
460+
# Pretty print json event
461+
#pretty: false
462+
463+
# Configure escaping html symbols in strings.
464+
#escape_html: true
465+
452466
# Metadata update configuration. Metadata do contain leader information
453467
# deciding which broker to use when publishing.
454468
#metadata:
@@ -551,6 +565,14 @@ output.elasticsearch:
551565
# Boolean flag to enable or disable the output module.
552566
#enabled: true
553567

568+
# Configure JSON encoding
569+
#codec.json:
570+
# Pretty print json event
571+
#pretty: false
572+
573+
# Configure escaping html symbols in strings.
574+
#escape_html: true
575+
554576
# The list of Redis servers to connect to. If load balancing is enabled, the
555577
# events are distributed to the servers in the list. If one server becomes
556578
# unreachable, the events are distributed to the reachable servers only.
@@ -652,6 +674,14 @@ output.elasticsearch:
652674
# Boolean flag to enable or disable the output module.
653675
#enabled: true
654676

677+
# Configure JSON encoding
678+
#codec.json:
679+
# Pretty print json event
680+
#pretty: false
681+
682+
# Configure escaping html symbols in strings.
683+
#escape_html: true
684+
655685
# Path to the directory where to save the generated files. The option is
656686
# mandatory.
657687
#path: "/tmp/beatname"
@@ -679,8 +709,13 @@ output.elasticsearch:
679709
# Boolean flag to enable or disable the output module.
680710
#enabled: true
681711

682-
# Pretty print json event
683-
#pretty: false
712+
# Configure JSON encoding
713+
#codec.json:
714+
# Pretty print json event
715+
#pretty: false
716+
717+
# Configure escaping html symbols in strings.
718+
#escape_html: true
684719

685720
#================================= Paths ======================================
686721

libbeat/docs/outputconfig.asciidoc

+16
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ Increasing the compression level will reduce the network usage but will increase
138138

139139
The default value is 0.
140140

141+
===== `escape_html`
142+
143+
Configure escaping of HTML in strings. Set to `false` to disable escaping.
144+
145+
The default value is `true`.
146+
147+
141148
===== `worker`
142149

143150
The number of workers per configured host publishing events to Elasticsearch. This
@@ -466,6 +473,12 @@ Increasing the compression level will reduce the network usage but will increase
466473

467474
The default value is 3.
468475

476+
===== `escape_html`
477+
478+
Configure escaping of HTML in strings. Set to `false` to disable escaping.
479+
480+
The default value is `true`.
481+
469482
===== `worker`
470483

471484
The number of workers per configured host publishing events to Logstash. This
@@ -1187,13 +1200,16 @@ codec. By default the `json` codec is used.
11871200

11881201
*`json.pretty`*: If `pretty` is set to true, events will be nicely formatted. The default is false.
11891202

1203+
*`json.escape_html`*: If `escape_html` is set to false, html symbols will not be escaped in strings. The default is true.
1204+
11901205
Example configuration that uses the `json` codec with pretty printing enabled to write events to the console:
11911206

11921207
[source,yaml]
11931208
------------------------------------------------------------------------------
11941209
output.console:
11951210
codec.json:
11961211
pretty: true
1212+
escape_html: false
11971213
------------------------------------------------------------------------------
11981214

11991215
*`format.string`*: Configurable format string used to create a custom formatted message.

0 commit comments

Comments
 (0)