首页 > 解决方案 > Jmeter 5.3:从请求 URL 中提取运行时“code_challenge”URL 参数值,该值未在任何响应中显示

问题描述

我们有一个 URL 参数作为“code_challenge”,它在运行时生成,我们需要提取这个值,以便在下次运行时可以处理它。但是,由于此代码值未在任何先前的请求/响应中捕获,并且需要在运行时提取,因此无法理解如何实现。

尝试了常规提取器选择 URL 单选按钮,但它从记录的脚本中捕获值。

后续步骤:

  1. 使用 Blazmeter 录制脚本(浏览 URL xx.com>单击登录)
  2. 重定向到其中一个 URL 具有“code_Challenge”参数和运行时值的 URL)第一个 URL 是:accounts-xx.com/oauth2/oidcdiscovery/.well-known/openid-configuration > 响应没有有任何参数值
  3. 第二个网址是: https ://accounts-xx.com/oauth2/authorize?response_type=code&client_id=zzzz&scope=ituytutut&redirect_uri=xx.com/callBack&code_challenge_method=ooo&**code_challenge=dsfsdlfhl **
  4. 在上面的第 3 点 url 中,Code_challenge 值是在从浏览器执行步骤时在运行时生成的。但是,如果重播已经生成代码值的录制脚本,则其他请求将失败。因此,需要获取获取的代码值。

code_challenge 是从 WS02 服务生成的。

Jmeter版本:5.3

请提出建议,或者我们是否需要使用 Selenium webdriver 集成。

在此处输入图像描述

从记录的脚本中提取值的正则表达式: 在此处输入图像描述

标签: jmeter

解决方案


  1. 根据缓解授权代码拦截攻击文章:

    code_challenge 客户端创建并记录一个秘密加密随机字符串(code_verifier),然后使用 URL 安全 base64 编码对其进行编码,以将其转换为 code_challenge。

  2. 根据WSO2 IS 服务器文章中的 PKCE

    1.Plain:
    
    If a code_challenge method is mention as plain or not mention at all it will take this plain value. Then code_challenge will like:
    
    code_challenge = code_verifier
    
    2. SHA256:
    
    To have the code_challenge as SHA256, we should mention this in request otherwise plain value will be assumed.For SHA256 code challenge will be like
    
    code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))
    
    Here base64url is same as base64encoding(used so that all machine can identify as same value) but trailing “=” will be removed and “+” & “/” are placed by “-” & “_” to avoid unnecessary length in URL.(otherwise ‘+’ becomes ‘%2B’, ‘/’ becomes ‘%2F’ and ‘=’ becomes ‘%3D in URL)
    
    As much as possible, it is better to select the code challenge method as SHA256 then the flow will become more secure and hard to guess(if someone try to brute force it)
    

所以我认为您需要添加JSR223 PreProcessorcode_challenge并使用您的服务器使用的Groovy 语言算法计算/生成,将值存储到 JMeter 变量中并在请求中使用它。


推荐阅读