RESTCONF/Yangdata endpoints not working properly with URL encoding

91 views Asked by At

Lets take this URL for example

https://<ip>/restconf/data/Cisco-IOS-XE-native:native/interface/GigabitEthernet=1

If i send a request to a similar endpoint using the internal library we've been using the server doesn't understand it since the = is encoded to %3D but making the same request on the CLI with curl works fine.

I'm not understanding why it's an issue, isn't = supposed to be encoded in a URL anyway? Is it something to do with the library treating it as a query?

1

There are 1 answers

0
predi On

The = represents a special character with special meaning in a RESTCONF URI. If you encode it as %3D, you take that special meaning away and reduce it to just a character. The only case where you would do that is when a list's key value or a leaf-list's value contain this character and you are referencing such an instance in your URI.

You are only allowed to use = when referencing list and leaf-list instances - and you do not percent encode it when you do use it.

In your case, GigabitEthernet would be expected to represent a list/leaf-list, with its key/type accepting 1 as a valid value. Both native and interface would be (and can only be) containers (or anydata).

RFC8040, Section 3.5.3, Encoding Data Resource Identifiers in the Request URI describes this in detail.

Here are the examples from the same section:

Examples:

 container top {
     list list1 {
         key "key1 key2 key3";
          ...
          list list2 {
              key "key4 key5";
              ...
              leaf X { type string; }
          }
      }
      leaf-list Y {
        type uint32;
      }
  }

For the above YANG definition, the container "top" is defined in the "example-top" YANG module, and a target resource URI for leaf "X" would be encoded as follows:

  /restconf/data/example-top:top/list1=key1,key2,key3/list2=key4,key5/X

For the above YANG definition, a target resource URI for leaf-list "Y" would be encoded as follows:

  /restconf/data/example-top:top/Y=instance-value

The following example shows how reserved characters are percent-encoded within a key value. The value of "key1" contains a comma, single-quote, double-quote, colon, double-quote, space, and forward slash (,'":" /). Note that double-quote is not a reserved character and does not need to be percent-encoded. The value of "key2" is the empty string, and the value of "key3" is the string "foo".

Example URL:

 /restconf/data/example-top:top/list1=%2C%27"%3A"%20%2F,,foo

Note the last example in particular. You would need to percent encode a =, if it appears after list1= in its key value.

Note that also that these are not parts of a query - they are path segments (RFC3986 terms).