Skip to content

Relax escaping of values to enable limited access to the shell for AppDynamnics config#911

Merged
dmikusa merged 1 commit intomainfrom
gh_issue_904
Oct 18, 2021
Merged

Relax escaping of values to enable limited access to the shell for AppDynamnics config#911
dmikusa merged 1 commit intomainfrom
gh_issue_904

Conversation

@dmikusa
Copy link
Contributor

@dmikusa dmikusa commented Oct 12, 2021

Previous PRs escaped configuration values for AppD. This was done to support things like names with spaces and other characters that, if used, would result in a broken start command.

The PR broke a use case which was documented for the node or tier name. In some cases, you may want to set the node or tier name to a dynamic value that is loaded at runtime so that you can incorporate things like the application instance index. For example DCX:$(echo $VCAP_APPLICATION | jq -r '.application_name'):$(echo $VCAP_APPLICATION | jq -r '.instance_index').

This new PR will use Shellwords.escape(..) on the value for all properties unless that property value contains what looks like a subshell $(..) or environment variable ${..} reference. If it looks like a subshell or env variable is being referenced, we will not escape but just wrap the value in escaped quotes. We wrap it in escaped quotes in case the shell variable or subshell returns something which includes spaces. This is not perfect though, and you need to be careful if using subshell/env variables, you should ensure the output is properly escaped.

For example:

  • DCX:$(echo $VCAP_APPLICATION | jq -r '.application_name'):$(echo $VCAP_APPLICATION | jq -r '.instance_index')
  • $(echo 'Hello world!') and stuff becomes \"$(echo 'Hello world!') and stuff\"
  • --> ${SOME_VAR} <-- becomes \"--> ${SOME_VAR} <--\"

Resolves #904

Signed-off-by: Daniel Mikusa dmikusa@vmware.com

…pDynamnics config

[Previous PRs escaped configuration values for AppD](#870). This was done to support things like names with spaces and other characters that, if used, would result in a broken start command.

The PR broke a use case which was documented for the node or tier name. In some cases, you may want to set the node or tier name to a dynamic value that is loaded at runtime so that you can incorporate things like the application instance index. For example `DCX:$(echo $VCAP_APPLICATION | jq -r '.application_name'):$(echo $VCAP_APPLICATION | jq -r '.instance_index')`.

This new PR will use `Shellwords.escape(..)` on the value for all properties unless that property value contains what looks like a subshell `$(..)` or environment variable `${..}` reference. If it looks like a subshell or env variable is being referenced, we will not escape but just wrap the value in escaped quotes. We wrap it in escaped quotes in case the shell variable or subshell returns something which includes spaces. This is not perfect though, and you need to be careful if using subshell/env variables, you should ensure the output is properly escaped.

For example:
- `DCX:$(echo $VCAP_APPLICATION | jq -r '.application_name'):$(echo $VCAP_APPLICATION | jq -r '.instance_index')`
- `$(echo 'Hello world!') and stuff` becomes `\"$(echo 'Hello world!') and stuff\"`
- `--> ${SOME_VAR} <--` becomes `\"--> ${SOME_VAR} <--\"`

Signed-off-by: Daniel Mikusa <dmikusa@vmware.com>
@dmikusa dmikusa mentioned this pull request Oct 12, 2021
@dmikusa dmikusa merged commit ba24874 into main Oct 18, 2021
@dmikusa dmikusa deleted the gh_issue_904 branch October 18, 2021 17:25
ramonskie pushed a commit that referenced this pull request Dec 4, 2025
…pDynamnics config (#911)

[Previous PRs escaped configuration values for AppD](#870). This was done to support things like names with spaces and other characters that, if used, would result in a broken start command.

The PR broke a use case which was documented for the node or tier name. In some cases, you may want to set the node or tier name to a dynamic value that is loaded at runtime so that you can incorporate things like the application instance index. For example `DCX:$(echo $VCAP_APPLICATION | jq -r '.application_name'):$(echo $VCAP_APPLICATION | jq -r '.instance_index')`.

This new PR will use `Shellwords.escape(..)` on the value for all properties unless that property value contains what looks like a subshell `$(..)` or environment variable `${..}` reference. If it looks like a subshell or env variable is being referenced, we will not escape but just wrap the value in escaped quotes. We wrap it in escaped quotes in case the shell variable or subshell returns something which includes spaces. This is not perfect though, and you need to be careful if using subshell/env variables, you should ensure the output is properly escaped.

For example:
- `DCX:$(echo $VCAP_APPLICATION | jq -r '.application_name'):$(echo $VCAP_APPLICATION | jq -r '.instance_index')`
- `$(echo 'Hello world!') and stuff` becomes `\"$(echo 'Hello world!') and stuff\"`
- `--> ${SOME_VAR} <--` becomes `\"--> ${SOME_VAR} <--\"`

Signed-off-by: Daniel Mikusa <dmikusa@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Escaping in AppD UPS

1 participant