Skip to content

Commit

Permalink
[8.12] [Fleet] Logstash Output - being compliant to RFC-952 (#176298) (
Browse files Browse the repository at this point in the history
…#176323)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Fleet] Logstash Output - being compliant to RFC-952
(#176298)](#176298)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Alex
S","email":"Terilia@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-02-06T16:33:56Z","message":"[Fleet]
Logstash Output - being compliant to RFC-952 (#176298)\n\n##
Summary\r\n\r\nThe logstash output in fleet was not following
the\r\n[RFC-952](https://www.rfc-editor.org/rfc/rfc952) correctly,
only\r\naccepting lowercase url's for the hostname, even though
according to the\r\nstandard, this should be
irrelevant.\r\n\r\nAdditionally added two new unit tests, to check that
this behaviour is\r\ncompliant in the future as well.\r\n\r\n\r\n## Fix
explanation\r\n\r\nThe issue was in the past that the URL Type in nodejs
is automatically\r\nlowercase, and then the value of the form is or the
string provided is\r\nchecked against this url type. The types behaviour
is explained
here:\r\nhttps://nodejs.org/api/url.html#the-whatwg-url-api\r\n\r\nAs we
would like to be case insensitive, in the check, the value is
also\r\nlowerecased with: val.toLowerCase() to pass the check\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [X] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"55429179ba30ca3a922f6daf44ce17f8d5f19507","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","backport:prev-minor","v8.13.0"],"title":"[Fleet]
Logstash Output - being compliant to
RFC-952","number":176298,"url":"https://github.com/elastic/kibana/pull/176298","mergeCommit":{"message":"[Fleet]
Logstash Output - being compliant to RFC-952 (#176298)\n\n##
Summary\r\n\r\nThe logstash output in fleet was not following
the\r\n[RFC-952](https://www.rfc-editor.org/rfc/rfc952) correctly,
only\r\naccepting lowercase url's for the hostname, even though
according to the\r\nstandard, this should be
irrelevant.\r\n\r\nAdditionally added two new unit tests, to check that
this behaviour is\r\ncompliant in the future as well.\r\n\r\n\r\n## Fix
explanation\r\n\r\nThe issue was in the past that the URL Type in nodejs
is automatically\r\nlowercase, and then the value of the form is or the
string provided is\r\nchecked against this url type. The types behaviour
is explained
here:\r\nhttps://nodejs.org/api/url.html#the-whatwg-url-api\r\n\r\nAs we
would like to be case insensitive, in the check, the value is
also\r\nlowerecased with: val.toLowerCase() to pass the check\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [X] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"55429179ba30ca3a922f6daf44ce17f8d5f19507"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.13.0","branchLabelMappingKey":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/176298","number":176298,"mergeCommit":{"message":"[Fleet]
Logstash Output - being compliant to RFC-952 (#176298)\n\n##
Summary\r\n\r\nThe logstash output in fleet was not following
the\r\n[RFC-952](https://www.rfc-editor.org/rfc/rfc952) correctly,
only\r\naccepting lowercase url's for the hostname, even though
according to the\r\nstandard, this should be
irrelevant.\r\n\r\nAdditionally added two new unit tests, to check that
this behaviour is\r\ncompliant in the future as well.\r\n\r\n\r\n## Fix
explanation\r\n\r\nThe issue was in the past that the URL Type in nodejs
is automatically\r\nlowercase, and then the value of the form is or the
string provided is\r\nchecked against this url type. The types behaviour
is explained
here:\r\nhttps://nodejs.org/api/url.html#the-whatwg-url-api\r\n\r\nAs we
would like to be case insensitive, in the check, the value is
also\r\nlowerecased with: val.toLowerCase() to pass the check\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [X] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"55429179ba30ca3a922f6daf44ce17f8d5f19507"}}]}]
BACKPORT-->

Co-authored-by: Alex S <Terilia@users.noreply.github.com>
  • Loading branch information
kibanamachine and Terilia authored Feb 6, 2024
1 parent 9c1c90b commit ea7b6c4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ describe('Output form validation', () => {

expect(res).toBeUndefined();
});

it('should work with hostnames using uppercase letters', () => {
const res = validateLogstashHosts(['tEsT.fr:9200', 'TEST2.fr:9200', 'teSt.fR:9999']);

expect(res).toBeUndefined();
});

it('should throw for invalid hosts starting with http', () => {
const res = validateLogstashHosts(['https://test.fr:5044']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function validateLogstashHosts(value: string[]) {

const url = new URL(`http://${val}`);

if (url.host !== val) {
if (url.host !== val.toLowerCase()) {
throw new Error('Invalid host');
}
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/fleet/server/types/models/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ describe('Output model', () => {
expect(validateLogstashHost('test.fr:5044')).toBeUndefined();
});

it('should support valid host with uppercase letters', () => {
expect(validateLogstashHost('tEsT.fr:5044')).toBeUndefined();
});

it('should return an error for an invalid host', () => {
expect(validateLogstashHost('!@#%&!#!@')).toMatchInlineSnapshot(`"Invalid Logstash host"`);
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/types/models/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function validateLogstashHost(val: string) {
try {
const url = new URL(`http://${val}`);

if (url.host !== val) {
if (url.host !== val.toLowerCase()) {
return 'Invalid host';
}
} catch (err) {
Expand Down

0 comments on commit ea7b6c4

Please sign in to comment.