Javascript 分配给window.location的代码是否易受XSS攻击?

Javascript 分配给window.location的代码是否易受XSS攻击?,javascript,xss,Javascript,Xss,有人能告诉我这个代码是否易受攻击吗?。如果是,请给出一些XSS示例,以便我能理解 代码页URL: https://myweb.com/auth?redirect_uri=https://otherurl.com/sdfdsf/sdfsdf 此代码易受XSS攻击吗 放弃密码 //Jquery代码 $“放弃密码”。单击函数{ var重定向URI=https://otherurl.com/sdfdsf/sdfsdf,URLMatch=redirectUri.match/^.*.com |.ca/; i

有人能告诉我这个代码是否易受攻击吗?。如果是,请给出一些XSS示例,以便我能理解

代码页URL:

https://myweb.com/auth?redirect_uri=https://otherurl.com/sdfdsf/sdfsdf 此代码易受XSS攻击吗

放弃密码 //Jquery代码 $“放弃密码”。单击函数{ var重定向URI=https://otherurl.com/sdfdsf/sdfsdf,URLMatch=redirectUri.match/^.*.com |.ca/; ifURLMatch{ window.location=URLMatch[0]+/forgotPassword; } };
如果此代码是自动生成的,以便从页面URL的查询参数redirect_uri读取redirectUri的值https://myweb.com/auth?redirect_uri=... 如果不进行编码或转义,并且正则表达式保持这种状态,即必须匹配.com或.ca,则您可能容易受到XSS攻击

这是一个威胁模型:

用户转到https://myweb.com/auth?redirect_uri=javascript:alert42//.com

然后在https://myweb.com/auth 脚本从URL提取redirect_uri参数,并将其提供给不安全的Mustache模板。e、 g

const mustache=所需胡须; 常量模板=` $“放弃密码”。单击函数{ var redirectUri='{{url}}',URLMatch=redirectUri.match/^..*.com |.ca/; ifURLMatch{ window.location=URLMatch[0]+/forgotPassword; } }; `; const jquery_code=mustache.rendertemplate{ url:new URLSearchParamswindow.location.search.get'redirect\u uri' }; 这就是jquery_代码变量包含的内容:

$“放弃密码”。单击函数{ var redirectUri='javascript:alert42/.com',URLMatch=redirectUri.match/^.*.com |.ca/; ifURLMatch{ window.location=URLMatch[0]+/forgotPassword; } }; 让我们看看如果注入页面会发生什么:我决定登录控制台,脚本将分配给window.location。复制/粘贴并自己运行到控制台中,看看会发生什么

$“放弃密码”。单击函数{ var redirectUri='javascript:alert42/.com',URLMatch=redirectUri.match/^.*.com |.ca/; ifURLMatch{ //window.location=URLMatch[0]+/forgotPassword; console.log `location=${URLMatch[0]+/forgotPassword}` } };
forgotPassword如果此代码是自动生成的,以便从页面URL的查询参数redirect_uri读取redirectUri的值https://myweb.com/auth?redirect_uri=... 如果不进行编码或转义,并且正则表达式保持这种状态,即必须匹配.com或.ca,则您可能容易受到XSS攻击

这是一个威胁模型:

用户转到https://myweb.com/auth?redirect_uri=javascript:alert42//.com

然后在https://myweb.com/auth 脚本从URL提取redirect_uri参数,并将其提供给不安全的Mustache模板。e、 g

const mustache=所需胡须; 常量模板=` $“放弃密码”。单击函数{ var redirectUri='{{url}}',URLMatch=redirectUri.match/^..*.com |.ca/; ifURLMatch{ window.location=URLMatch[0]+/forgotPassword; } }; `; const jquery_code=mustache.rendertemplate{ url:new URLSearchParamswindow.location.search.get'redirect\u uri' }; 这就是jquery_代码变量包含的内容:

$“放弃密码”。单击函数{ var redirectUri='javascript:alert42/.com',URLMatch=redirectUri.match/^.*.com |.ca/; ifURLMatch{ window.location=URLMatch[0]+/forgotPassword; } }; 让我们看看如果注入页面会发生什么:我决定登录控制台,脚本将分配给window.location。复制/粘贴并自己运行到控制台中,看看会发生什么

$“放弃密码”。单击函数{ var redirectUri='javascript:alert42/.com',URLMatch=redirectUri.match/^.*.com |.ca/; ifURLMatch{ //window.location=URLMatch[0]+/forgotPassword; console.log `location=${URLMatch[0]+/forgotPassword}` } };
放弃密码我想你改变了实际的代码,也改变了最相关的部分。重定向URI是从用户输入窗口分配的。位置可能是?在实际代码中,我猜,在这种情况下,domxss确实容易受到攻击。虽然这可能不容易利用,但我认为您更改了实际代码,并且更改了最相关的部分。重定向URI是从用户输入窗口分配的。位置可能是?在实际代码中,我猜,在这种情况下,domxss确实容易受到攻击。虽然这可能不容易利用。非常感谢兄弟谢谢兄弟