Keeper-Security/keeper-sdk-dotnet

Using a colon inside a custom field name is interpreted by Keeper as a new custom field

Closed this issue · 7 comments

When using, for a custom field named company:customfield:salt and a value of false, using this to set it:

$custom = "company:customfield:salt : true"
Add-KeeperRecord -UpdateOnly -Title $title -Login $login -GeneratePassword -Custom $custom

It creates a new custom field named "company" and a value of "customfield:salt : true"
How to escape this properly?

Add-KeeperRecord function has been refactored recently to support record types.
The custom field array is defined as [string[]] $Fields, where a field has format NAME=VALUE
So, colon is not an issue anymore (the equal sign is)
We will fix this issue by supporting quotes around name and/or value

The older code parses custom fields as

    if ($Custom) {
       foreach($customField in $Custom) {
         $pos = $customField.IndexOf(':')
         if ($pos -gt 0 -and $pos -lt $customField.Length) {
           $_ = $record.SetCustomField($customField.Substring(0, $pos), $customField.Substring($pos + 1))
         }
       }
     }

I don't think there is a way to escape colon

As of which commit is it possible to set quotes around the name/value?

And how would that look like in Powershell?
Something like this comes to mind, but no idea if I'm thinking rightly about that.

$customfields = "`"company:customfield:salt`" : `"true`""
Add-KeeperRecord -UpdateOnly -Title $title -Login $login -GeneratePassword -Custom $customfields

hi @Surowa
I'll let @sk-keeper to reply to your question. But in the mean time can you let me know what use case are you trying to solve by having : in your custom field names? Maybe we are missing something?

could be replaced with

        if ($Custom) {
            foreach($customField in $Custom) {
				if (-not $customField) {
					continue
				}
				$pos = 1
				if ($customField[0] -in ('"', '''', '`')) {
					$quotePos = $customField.indexOf($customField[0], $pos)
					if ($quotePos -gt 0) {
						$pos = $quotePos + 1
					}
				}
                $pos = $customField.IndexOf(':', $pos)
                if ($pos -gt 0 -and $pos -lt $customField.Length) {
					$fieldName = $customField.Substring(0, $pos).Trim()
					if ($fieldName[0] -in ('"', '''', '`')) {
						$fieldName = $fieldName.Trim($fieldName[0])
					} 
                    $_ = $record.SetCustomField($fieldName, $customField.Substring($pos + 1))
                }
            }
        }

Example:

Add-KeeperRecord -UpdateOnly -Title "Title" -Custom '`aaa:bbb:ccc`:ddd'

@maksimu internally we use colons in our custom field names to distinguish internal custom fields from external custom fields in Keeper. Having colons parsed correctly in the PowerCommander allows us to quickly and easily manage these records from Powershell scripts as well.
@sk-keeper Thanks! That clears it up. An improvement like that would be very desirable!

Do I need to submit a PR? Or can you do it @sk-keeper ?

This code cannot be merged into the repository.
The latest version of the Add-KeeperRecord cmdlet does not use a colon as a key-value separator. It uses = equal sign instead.