XML API 包含特殊字符的密码问题

XML API 包含特殊字符的密码问题

87342
Created On 09/25/18 20:36 PM - Last Modified 03/26/21 17:01 PM


Symptom


用户在 API 使用时无法生成密钥或使用基本身份验证 XML API 。T他的用户可能会遇到以下错误之一
:–无效凭据
-参数密码丢失值
-无法解决主机名(从命令行运行从cURL)

相同的用户名和密码将适用于 SSH 和Web界面登录。

示例
:$卷曲-k"http://10.129.80.155/api/?type=keygen&user=user01&password=user#01"
<response status='error' code='403'><result><msg>无效凭据。</msg></result></response>


或者你可能会得到一个丢失的参数错误:

例如
:$Curl-k"http://10.129.80.155/api/?type=keygen&user=user02&password=#02user"
<response status='error' code='400'><result><msg>参数"密码"缺少值。</msg></result></response>

或者,在使用基本身份验证时,您将无法解决主机名称

:$curl-k"http://user01:user#01@10.129.80.155//api/?type=op&cmd" <show><system><info></info></system></show>
卷发:(6)无法解决主机问题:用户01 https://198.51.100.1/api/?type=keygen&user=apiuser&password=&apiuser(


在浏览器中运行)

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<response status="error" code="400">
<result>
<msg>Missing value for parameter "password".</msg>
</result>
</response>
  用户添加的图像
https://198.51.100.1/api/?type=keygen&user=apiuser&password=api#user( 在浏览器中运行)
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<response status="error" code="403">
<result>
<msg>Invalid Credential</msg>
</result>
</response>
  
用户添加的图像


Cause


在所有情况下,密码都包含特殊字符。 API当密码包含#和+等特殊字符时,关键一代将失败。 这不是一个 PAN-OS 具体问题。 这是由于浏览器和cURL处理特殊字符的方式。 这是因为这些是用作一般或子划界线的保留字符。

RFC定义划界器列表:https://tools.ietf.org/html/rfc3986#section-2.2:https://tools.ietf.org/html/rfc3986#section-3.5
RFC在第

3.5 节中: A 片段标识符组件由数字符号"#"字符的存在表示,并在末尾终止 URL 。 现在,看看cURL官方文件:https://curl.haxx.se/。

当一个碎片 URL 传递到它时,Curl 支持碎片很好,但碎片部分实际上从未通过电线发送,因此无论是否存在,它都不会对 cURL 的操作产生影响。 因此,"#"永远不会通过电线发送,导致这种行为。

当使用这些没有 URL 编码,你可以看到浏览器实际上并没有发送整个 URL (在这种情况下的密码)。 在下面的示例 HTTP 中,已启用以用于演示目的,数据包捕获的易用性显示 HTTP 有效载荷。

示例 1:用户名:用户名 2 和密码:用户+2

浏览器:
用户添加的图像

在发送请求的客户端捕获的数据包 GET :
用户添加的图像

如果您查看密码部分,浏览器会截断"用户"的密码。

示例2:用户名:用户名3和密码用户#3

浏览器:
用户添加的图像

在发送请求的客户端拍摄的数据包捕获 GET :
用户添加的图像

如果您查看密码部分,浏览器会截断"用户"的密码。 因此,这个问题是由于浏览器和cURL对特殊字符的解释。


Resolution


以下是保留字符集的快速参考:

 reserved    = gen-delims / sub-delims
 gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"
 sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
                  / "*" / "+" / "," / ";" / "="

如果 URI 组件的数据与保留字符作为分界器的目的相冲突,则必须编码相互冲突的数据 URI 。 在这种情况下,如果密码包含保留的字符,则必须对它们进行编码,然后用作输入。

例如,如果密码包含"#"和"+"等特殊字符, URL 则分别使用编码%23%26。

示例 API 请求:
https://198.51.100.1/api/?type=keygen&user=apiuser&password=api%23 使用者



Additional Information


有关其他信息,以下是一些供参考的文章
pan-os :https://docs.paloaltonetworks.com//8-1/ - pan-os panorama api/开始与 pan-os -xml-api/获取您的 api-key

轻松编码和解码的URI:
https://www.url-encode-decode.com/

所有特殊字符编码的列表 HTML
:https://www.w3schools.com/tags/ref_urlencode.asp
 


Actions
  • Print
  • Copy Link

    https://knowledgebase.paloaltonetworks.com/KCSArticleDetail?id=kA10g000000CliMCAS&lang=zh_CN&refURL=http%3A%2F%2Fknowledgebase.paloaltonetworks.com%2FKCSArticleDetail

Choose Language