CodeQL 文档

不安全的 URL 白名单

ID: js/angular/insecure-url-whitelist
Kind: problem
Security severity: 7.5
Severity: warning
Precision: very-high
Tags:
   - security
   - frameworks/angularjs
   - external/cwe/cwe-183
   - external/cwe/cwe-625
Query suites:
   - javascript-code-scanning.qls
   - javascript-security-extended.qls
   - javascript-security-and-quality.qls

点击查看 CodeQL 代码库中的查询

AngularJS 使用过滤器来确保用于获取 AngularJS 模板和其他脚本运行 URL 的 URL 是安全的。其中一个过滤器是允许的 URL 模式白名单。

过于宽松的 URL 模式会导致安全漏洞。

建议

使白名单 URL 模式尽可能严格。

示例

以下示例展示了具有过于宽松的白名单 URL 模式的 AngularJS 应用程序。

angular.module('myApp', [])
    .config(function($sceDelegateProvider) {
        $sceDelegateProvider.resourceUrlWhitelist([
            "*://example.org/*", // BAD
            "https://**.example.com/*", // BAD
            "https://example.**", // BAD
            "https://example.*" // BAD
        ]);
    });

这存在问题,因为这四个模式分别匹配以下恶意 URL:

  • javascript://example.org/a%0A%0Dalert(1) (%0A%0D 是换行符)

  • https://evil.com/?ignore=://example.com/a

  • https://example.evil.com

  • https://example.evilTld

参考资料

  • ©GitHub, Inc.
  • 条款
  • 隐私