diff --git a/netlify/functions/qrcode-generate.js b/netlify/functions/qrcode-generate.js
index ba7c9a6..79aafbe 100644
--- a/netlify/functions/qrcode-generate.js
+++ b/netlify/functions/qrcode-generate.js
@@ -47,11 +47,12 @@ function withTimeout(promise, timeoutMs) {
}
exports.handler = withAuth(async (event, context, { body }) => {
+ // 405 优先于 Schema 验证(确保 HTTP 方法错误优先返回)
if (event.httpMethod !== 'POST') {
throw new AuthError('Method Not Allowed', 405);
}
- // withAuth 不在这里使用 validateSchema,确保非 POST 请求先返回 405。
+ // 手动调用 Schema 验证,确保 405 已经检查过
validateInput(qrcodeSchema, body);
const size = normalizeSize(body.size);
@@ -76,4 +77,4 @@ exports.handler = withAuth(async (event, context, { body }) => {
console.error('[qrcode-generate] QR code generation failed:', error.message);
throw error;
}
-});
+}, { requireAuth: true });
diff --git a/src/giffgaff/js/modules/ui-controller.js b/src/giffgaff/js/modules/ui-controller.js
index 7c67cfd..8f645b2 100644
--- a/src/giffgaff/js/modules/ui-controller.js
+++ b/src/giffgaff/js/modules/ui-controller.js
@@ -431,7 +431,13 @@ export class UIController {
const gen = ++this._qrGeneration;
try {
- const result = await generateQRCodeWithFallback(data, size);
+ const labels = {
+ alt: tl('eSIM 二维码'),
+ ariaLabel: tl('eSIM 安装二维码'),
+ tooltipAlt: tl('eSIM 二维码放大预览')
+ };
+
+ const result = await generateQRCodeWithFallback(data, size, labels);
if (gen !== this._qrGeneration) return; // 防止并发调用干扰
if (result.tooltip && typeof this.showTooltipElement === 'function' && typeof this.hideTooltipElement === 'function') {
@@ -444,12 +450,20 @@ export class UIController {
} catch (error) {
if (gen !== this._qrGeneration) return;
console.error('[Giffgaff] QR code generation failed:', error);
- this.elements.qrcode.innerHTML = `
-
-
- ${t('giffgaff.app.qr.failed')}
-
- `;
+
+ // 使用 DOM API 创建元素,避免 innerHTML XSS 风险
+ const alertDiv = document.createElement('div');
+ alertDiv.className = 'alert alert-danger';
+
+ const icon = document.createElement('i');
+ icon.className = 'fas fa-exclamation-circle me-2';
+ alertDiv.appendChild(icon);
+
+ const message = document.createTextNode(t('giffgaff.app.qr.failed'));
+ alertDiv.appendChild(message);
+
+ this.elements.qrcode.innerHTML = '';
+ this.elements.qrcode.appendChild(alertDiv);
}
}
diff --git a/src/js/modules/qrcode-generator.js b/src/js/modules/qrcode-generator.js
index b19035d..8f93b84 100644
--- a/src/js/modules/qrcode-generator.js
+++ b/src/js/modules/qrcode-generator.js
@@ -100,6 +100,7 @@ function validateQRCodeData(data) {
/**
* 懒加载浏览器端 qrcode.js 库。
* 首次调用会插入 CDN script,后续调用复用同一个 Promise,避免重复加载。
+ * 修复 Promise 挂起问题:移除失效脚本、添加超时保护(Issue #75 根因修复)。
* @returns {Promise