sentrysoftware / metricshub

Universal Metrics Collection for OpenTelemetry
https://metricshub.com
GNU Affero General Public License v3.0
15 stars 4 forks source link

Add support for protecting double quotes and backslashes in password and username JSON fields `%{PASSWORD_JSON}` and `%{USERNAME_JSON}` #355

Closed NassimBtk closed 3 months ago

NassimBtk commented 3 months ago

Description

In our current implementation, the macros interpreter does not adequately protect JSON passwords that contain double quotes (") and backslashes (\). This issue can lead to connection issues due to malformed requests.

Here is an example of an HTTP body which can lead to the problem described above:

{
    "UserName":"%{USERNAME}",
    "Password":"%{PASSWORD}"
}

When %{PASSWORD} is replaced with the configured password that contains double quotes or backslashes, the interpretation will result in malformed JSON or improperly escaped characters.

Suggested solution

To address this issue, we suggest to introduce two macros, %{USERNAME_JSON} and %{PASSWORD_JSON}, that will ensure the proper escaping of special characters (double quotes and backslashes) in the password and username values during macro interpretation. The macros in the above example will look like this:

{
    "UserName":"%{USERNAME_JSON}",
    "Password":"%{PASSWORD_JSON}"
}

The Macro interpreter should be enhanced to escape double quotes and backslashes in the password and username values when replacing the %{PASSWORD_JSON} and %{USERNAME_JSON} macros with the actual password and username.

Implementation Steps (Java class: HttpMacrosUpdater)