{"record":{"id":"f64e00007d396eda","repo":"babalae/better-genshin-impact","slug":"js-url-manifest-json-http-allow","errorCode":null,"errorMessage":"当前JS脚本没有配置允许请求的URL，请在脚本的manifest.json中配置http_allowed_urls","messagePattern":"当前JS脚本没有配置允许请求的URL，请在脚本的manifest\\.json中配置http_allowed_urls","errorType":"exception","errorClass":"UnauthorizedAccessException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Script/Dependence/Http.cs","lineNumber":30,"sourceCode":"using Microsoft.Extensions.Logging;\n\nnamespace BetterGenshinImpact.Core.Script.Dependence;\n\npublic class Http\n{\n    private readonly ILogger<Http> _logger = App.GetLogger<Http>();\n\n    private void CheckHttpPermission(string url)\n    {\n        var currentProject = TaskContext.Instance().CurrentScriptProject;\n        if (!currentProject?.AllowJsHTTP ?? false)\n        {\n            throw new UnauthorizedAccessException(\"当前JS脚本不允许使用HTTP请求，请在调度器通用设置中启用“JS HTTP权限”\");\n        }\n        var allowedUrls = currentProject?.Project?.Manifest.HttpAllowedUrls ?? [];\n        if (allowedUrls.Length == 0)\n        {\n            throw new UnauthorizedAccessException(\"当前JS脚本没有配置允许请求的URL，请在脚本的manifest.json中配置http_allowed_urls\");\n        }\n        if (allowedUrls.Any(allowedUrl =>\n        {\n            // fuzzy match\n            var pattern = \"^\" + System.Text.RegularExpressions.Regex.Escape(allowedUrl).Replace(\"\\\\*\", \".*\") + \"$\";\n            _logger.LogDebug($\"[HTTP] 检查URL {url} 是否符合: {pattern}\");\n            var regex = new System.Text.RegularExpressions.Regex(pattern);\n            return regex.IsMatch(url);\n        }))\n        {\n            return;\n        }\n        throw new UnauthorizedAccessException($\"当前JS脚本不允许请求此URL: {url}，请在脚本的manifest.json中配置http_allowed_urls，当前允许的URL列表: [{string.Join(\", \", allowedUrls)}]\");\n    }\n\n    public class HttpReponse\n    {\n        public int status_code { get; set; }","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/Dependence/Http.cs#L12-L48","documentation":"Thrown as UnauthorizedAccessException by Http.CheckHttpPermission when AllowJsHTTP is enabled but the project's manifest.json has no http_allowed_urls entries (or the array is absent/empty). Even with global HTTP permission, each script must declare which URLs it may access — an empty allowlist blocks everything.","triggerScenarios":"HTTP permission is enabled in settings, but the script's manifest.json either has no http_allowed_urls field, has it set to an empty array [], or the manifest was not loaded correctly.","commonSituations":"Developer enabled JS HTTP permission but forgot to add URLs to manifest.json. Manifest file is malformed and the field wasn't parsed. Script was copied from another project without updating its URL allowlist.","solutions":["Add http_allowed_urls to the script's manifest.json with the required URL patterns.","Use wildcard patterns for flexible matching: \"https://api.example.com/*\".","Verify the manifest.json is valid JSON and the field name is exactly http_allowed_urls.","Reload the script project after editing manifest.json."],"exampleFix":"// before — manifest.json\n{\n  \"name\": \"my-script\",\n  \"version\": \"1.0\"\n}\n\n// after — manifest.json\n{\n  \"name\": \"my-script\",\n  \"version\": \"1.0\",\n  \"http_allowed_urls\": [\n    \"https://api.example.com/*\",\n    \"https://cdn.example.com/*\"\n  ]\n}","handlingStrategy":"validation","validationCode":"// Check URL allowlist configuration before HTTP calls\nvar project = TaskContext.Instance().CurrentScriptProject;\nvar allowedUrls = project?.Project?.Manifest.HttpAllowedUrls ?? [];\nif (allowedUrls.Length == 0)\n{\n    _logger.LogError(\"No http_allowed_urls configured in manifest.json\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var resp = http.Get(url, headers);\n}\ncatch (UnauthorizedAccessException ex) when (ex.Message.Contains(\"没有配置允许请求的URL\"))\n{\n    _logger.LogError(\"Add http_allowed_urls to manifest.json with required URL patterns.\");\n}","preventionTips":["Always configure http_allowed_urls in manifest.json when using HTTP.","Use wildcard patterns like https://api.example.com/* for flexibility.","Reload the script project after editing manifest.json."],"tags":["security","permission","http","config","manifest","allowlist"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}