Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver specific template escaping #4666

Merged
merged 22 commits into from
Oct 19, 2023

Conversation

bazsi
Copy link
Collaborator

@bazsi bazsi commented Oct 8, 2023

This is an alternative for #4664 which generalizes template-escape() to allow driver specific escaping modes and also makes it easy for drivers to request escaping of a template expansion.

The idea is to allow the http() destination to use templates in the url() parameter. Allowing unsanitized input in an URL string could pose a security risk, so doing URL encoding of the values make would make sense.

@bazsi bazsi force-pushed the driver-specific-template-escaping branch 2 times, most recently from c94b47c to 89a7410 Compare October 9, 2023 07:28
Signed-off-by: Balazs Scheidler <[email protected]>
In order to recurse into our grammar we can't use global variables to track
objects we are parsing into.

This solution uses the $0 value for rule actions to pass arguments to that
specific rule, this time the LogTemplate instance we need to parse into.

That way the LogTemplate instance would be separate even if we are
recursing into the same parts of the grammar.

A similar solution could potentially be established to all similar cases,
using global variables in a recursive grammar is not right.

Signed-off-by: Balazs Scheidler <[email protected]>
To be able to use separate grammar rules for template references
and inline templates.

Signed-off-by: Balazs Scheidler <[email protected]>
A top_level LogTemplate is one which is instantiated directly from
the configuration or by a driver. For embedded LogTemplate instances
(e.g. within function invocations), this is FALSE.

The idea is that some operations (e.g. escaping) are only performed
at the top level.

Signed-off-by: Balazs Scheidler <[email protected]>
With this patch it becomes possible to enable escaping from both the
LogTemplate side (e.g.  when template-escape(yes) is present in a template
statement) and the LogTemplateOptions side (e.g.  with the destination
driver specific template-escape()) option.

Previously only LogWriter supplied this setting and it only worked in case
of an inline template.  With this change, this works with all drivers that
support the `template_option` grammar rule.

Signed-off-by: Balazs Scheidler <[email protected]>
Earlier, template functions were performing escaping as a part of their
own expansion of macros/values. This means that a template-escape(yes)
template, with embedded template functions, the template functions received
its arguments in an escaped form.

For example this template:

    template t_escaped {
        template("$(echo $(length ${value}))");
        template-escape(yes)
   };

where $value contains characters that need to be escaped (e.g. quotes
or control characters), $(length) received the escaped format.

This patch changes this behaviour slightly by:
  1) embedded template expressions always get strings in an unescaped form
  2) the end result of functions are escaped at the top-level.

Signed-off-by: Balazs Scheidler <[email protected]>
This patch moves escaping to one layer higher, thereby ensuring a consistent
escaping implmentation and simplifying the lower layers.

Signed-off-by: Balazs Scheidler <[email protected]>
With this change the call-site of log_template_format_*() family of
functions can supply a custom escaping mechanism.

Signed-off-by: Balazs Scheidler <[email protected]>
@bazsi bazsi force-pushed the driver-specific-template-escaping branch from 89a7410 to 7be4356 Compare October 14, 2023 04:42
tests/light/src/syslog_ng_config/__init__.py Show resolved Hide resolved
lib/cfg-grammar.y Show resolved Hide resolved
lib/template/eval.c Outdated Show resolved Hide resolved
@alltilla alltilla merged commit 5e761f8 into syslog-ng:master Oct 19, 2023
19 checks passed
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Oct 20, 2023
Signed-off-by: Attila Szakacs <[email protected]>
alltilla added a commit to alltilla/syslog-ng that referenced this pull request Oct 24, 2023
Signed-off-by: Attila Szakacs <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants