fix: stop kiro auto-run on proxy error pages
This commit is contained in:
@@ -4,6 +4,7 @@ const KIRO_DESKTOP_AUTHORIZE_LISTENER_SENTINEL = 'data-multipage-kiro-desktop-au
|
||||
const KIRO_DESKTOP_ALLOW_TEXT_PATTERN = /allow access|authorize|continue|allow|允许访问|授权|继续/i;
|
||||
const KIRO_DESKTOP_LOADING_TEXT_PATTERN = /loading|redirecting|please wait|加载中|跳转中|请稍候/i;
|
||||
const KIRO_DESKTOP_CLOUDFRONT_403_TEXT_PATTERN = /403 error|the request could not be satisfied|generated by cloudfront/i;
|
||||
const KIRO_DESKTOP_AWS_REQUEST_ERROR_TEXT_PATTERN = /sorry,\s*there was an error processing your request\.?\s*please try again\.?|抱歉,处理您的请求时出错。请重试。?/i;
|
||||
|
||||
const KIRO_DESKTOP_EMAIL_INPUT_SELECTOR = [
|
||||
'input[placeholder="username@example.com"]',
|
||||
@@ -94,8 +95,30 @@ function findDesktopActionButton(options = {}) {
|
||||
return pool[0] || null;
|
||||
}
|
||||
|
||||
function isKiroDesktopAuthHost(hostname = '') {
|
||||
const normalized = String(hostname || '').trim().toLowerCase();
|
||||
return normalized === 'view.awsapps.com'
|
||||
|| normalized === 'login.awsapps.com'
|
||||
|| normalized === 'profile.aws.amazon.com'
|
||||
|| normalized === 'profile.aws'
|
||||
|| normalized.endsWith('.profile.aws.amazon.com')
|
||||
|| normalized.endsWith('.profile.aws')
|
||||
|| normalized === 'signin.aws.amazon.com'
|
||||
|| normalized === 'signin.aws'
|
||||
|| normalized.endsWith('.signin.aws.amazon.com')
|
||||
|| normalized.endsWith('.signin.aws');
|
||||
}
|
||||
|
||||
function detectDesktopFatalState(pageText = '', currentUrl = '', pageTitle = '') {
|
||||
const combinedText = `${pageTitle} ${pageText}`.replace(/\s+/g, ' ').trim();
|
||||
const isKiroAuthHost = isKiroDesktopAuthHost(location.hostname || '');
|
||||
if (isKiroAuthHost && KIRO_DESKTOP_AWS_REQUEST_ERROR_TEXT_PATTERN.test(combinedText)) {
|
||||
return {
|
||||
state: 'proxy_error_page',
|
||||
url: currentUrl,
|
||||
fatalMessage: 'Kiro 桌面授权页出现 AWS 请求异常,通常是当前代理 IP 或出口区域异常,请先切换代理后再重试。',
|
||||
};
|
||||
}
|
||||
if (KIRO_DESKTOP_CLOUDFRONT_403_TEXT_PATTERN.test(combinedText)) {
|
||||
return {
|
||||
state: 'cloudfront_403_page',
|
||||
@@ -204,8 +227,8 @@ function detectKiroDesktopAuthorizeState() {
|
||||
|
||||
async function getCurrentDesktopAuthorizeState() {
|
||||
const detected = detectKiroDesktopAuthorizeState();
|
||||
if (detected.state === 'cloudfront_403_page') {
|
||||
throw new Error(detected.fatalMessage || 'Kiro 桌面授权页出现 403。');
|
||||
if (detected.state === 'cloudfront_403_page' || detected.state === 'proxy_error_page') {
|
||||
throw new Error(detected.fatalMessage || 'Kiro 桌面授权页出现代理异常。');
|
||||
}
|
||||
if (detected.state === 'callback_error') {
|
||||
throw new Error(`Kiro 桌面授权回调失败:${detected.error || 'unknown_error'}`);
|
||||
|
||||
@@ -7,6 +7,7 @@ const KIRO_CONFIRM_CONTINUE_TEXT_PATTERN = /confirm and continue|确认并继续
|
||||
const KIRO_ALLOW_ACCESS_TEXT_PATTERN = /allow access|允许访问/i;
|
||||
const KIRO_SUCCESS_TEXT_PATTERN = /authorization successful|you may now close this window|you are now signed in|授权成功|可以关闭此窗口|已登录/i;
|
||||
const KIRO_CLOUDFRONT_403_TEXT_PATTERN = /403 error|the request could not be satisfied|generated by cloudfront/i;
|
||||
const KIRO_AWS_REQUEST_ERROR_TEXT_PATTERN = /sorry,\s*there was an error processing your request\.?\s*please try again\.?|抱歉,处理您的请求时出错。请重试。?/i;
|
||||
|
||||
const KIRO_EMAIL_INPUT_SELECTOR = [
|
||||
'input[placeholder="username@example.com"]',
|
||||
@@ -193,20 +194,39 @@ function findAuthorizationActionButton() {
|
||||
});
|
||||
}
|
||||
|
||||
function isKiroAwsAuthHost(hostname = '') {
|
||||
const normalized = String(hostname || '').trim().toLowerCase();
|
||||
return normalized === 'view.awsapps.com'
|
||||
|| normalized === 'login.awsapps.com'
|
||||
|| normalized === 'profile.aws.amazon.com'
|
||||
|| normalized === 'profile.aws'
|
||||
|| normalized.endsWith('.profile.aws.amazon.com')
|
||||
|| normalized.endsWith('.profile.aws')
|
||||
|| normalized === 'signin.aws.amazon.com'
|
||||
|| normalized === 'signin.aws'
|
||||
|| normalized.endsWith('.signin.aws.amazon.com')
|
||||
|| normalized.endsWith('.signin.aws');
|
||||
}
|
||||
|
||||
function detectKiroFatalPageState(pageText = '', currentUrl = '', pageTitle = '') {
|
||||
const combinedText = `${pageTitle} ${pageText}`.replace(/\s+/g, ' ').trim();
|
||||
const normalizedHost = String(location.hostname || '').trim().toLowerCase();
|
||||
const isAwsProfileHost = normalizedHost === 'profile.aws.amazon.com'
|
||||
|| normalizedHost === 'profile.aws'
|
||||
|| normalizedHost.endsWith('.profile.aws.amazon.com')
|
||||
|| normalizedHost.endsWith('.profile.aws');
|
||||
const isKiroAuthHost = isKiroAwsAuthHost(normalizedHost);
|
||||
const matchedSignals = [
|
||||
/403 error/i.test(combinedText),
|
||||
/the request could not be satisfied/i.test(combinedText),
|
||||
/generated by cloudfront/i.test(combinedText),
|
||||
].filter(Boolean).length;
|
||||
|
||||
if (matchedSignals >= 2 || (isAwsProfileHost && matchedSignals >= 1 && KIRO_CLOUDFRONT_403_TEXT_PATTERN.test(combinedText))) {
|
||||
if (isKiroAuthHost && KIRO_AWS_REQUEST_ERROR_TEXT_PATTERN.test(combinedText)) {
|
||||
return {
|
||||
state: 'proxy_error_page',
|
||||
url: currentUrl,
|
||||
fatalMessage: 'Kiro 注册页出现 AWS 请求异常,通常是当前代理 IP 或出口区域异常,请先切换代理后再重试。',
|
||||
};
|
||||
}
|
||||
|
||||
if (matchedSignals >= 2 || (isKiroAuthHost && matchedSignals >= 1 && KIRO_CLOUDFRONT_403_TEXT_PATTERN.test(combinedText))) {
|
||||
return {
|
||||
state: 'cloudfront_403_page',
|
||||
url: currentUrl,
|
||||
@@ -218,7 +238,8 @@ function detectKiroFatalPageState(pageText = '', currentUrl = '', pageTitle = ''
|
||||
}
|
||||
|
||||
function isKiroFatalState(state = '') {
|
||||
return state === 'cloudfront_403_page';
|
||||
return state === 'cloudfront_403_page'
|
||||
|| state === 'proxy_error_page';
|
||||
}
|
||||
|
||||
function getKiroFatalStateMessage(snapshot = {}) {
|
||||
@@ -228,6 +249,8 @@ function getKiroFatalStateMessage(snapshot = {}) {
|
||||
switch (snapshot?.state) {
|
||||
case 'cloudfront_403_page':
|
||||
return 'Kiro 注册页返回 403(CloudFront 拒绝请求),通常是当前代理 IP 或区域触发了 AWS 风控,请更换代理后重试。';
|
||||
case 'proxy_error_page':
|
||||
return 'Kiro 注册页出现 AWS 请求异常,通常是当前代理 IP 或出口区域异常,请先切换代理后再重试。';
|
||||
default:
|
||||
return `Kiro 页面出现异常状态:${snapshot?.state || 'unknown'}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user