在 Bug 赏金计划中可能让你付出高昂代价的 10 段 JavaScript
2024-1-20 15:57:58 Author: Ots安全(查看原文) 阅读量:18 收藏

向 bug 赏金猎人教授 JavaScript 涉及到关注该语言及其生态系统中通常与安全漏洞相关的部分。以下是 10 个 JavaScript 代码片段示例,每个示例都突出显示了 bug 赏金猎人可能感兴趣的不同方面:

  1. 通过 InnerHTML 的跨站脚本 (XSS)

    // Vulnerable to XSS if 'userInput' is not sanitizeddocument.getElementById('someElement').innerHTML = userInput;
  2. 通过 URL 操作进行基于 DOM 的 XSS

    // Vulnerable to DOM-based XSS if URL parameters are not properly handledvar userData = window.location.href.substring(window.location.href.indexOf("user=") + 5);document.getElementById('userDisplay').innerText = userData;
  3. 通过 eval() 进行 JavaScript 注入

    // Dangerous use of eval() with user-provided datavar userCode = getUserInput();eval(userCode);
  4. 原型污染

    // Vulnerable to prototype pollutionfunction mergeOptions(obj1, obj2) {   for (var prop in obj2) {       if (obj2.hasOwnProperty(prop)) {           obj1[prop] = obj2[prop];       }   }}
  5. 不安全的直接对象引用 (IDOR)

    // Using user input directly in an important operationvar userId = document.getElementById('userId').value;var userData = getUserData(userId); // Potential IDOR if not properly checked
  6. 客户端逻辑操作

    // Relying on client-side validation for important logicif (clientSideCheckPassed()) {   completeTransaction();}
  7. 本地存储中的敏感数据暴露

    // Storing sensitive data in local storagelocalStorage.setItem('sessionToken', sessionToken);
  8. 不安全的 CORS 政策

    // Setting a too permissive CORS policyapp.use((req, res, next) => { res.setHeader('Access-Control-Allow-Origin', '*'); next();});
  9. 将 document.write 与用户输入一起使用

    // Potential XSS vulnerability with document.writevar userInput = getUrlParameter("userInput"); // Assuming this function gets user input from URLdocument.write(userInput);
  10. 错误处理不当泄露敏感信息

    // Insecure error handling that could reveal sensitive informationtry {    performSensitiveOperation();} catch (error) {    console.log('Error:', error); // Logging detailed error information}

这些示例中的每一个都代表了 JavaScript 编码中可能导致漏洞的常见问题。漏洞赏金猎人应该熟悉这些模式,以便有效地识别和报告潜在的安全问题。

原文地址:

https://blog.hackxpert.com/2024/01/10-pieces-of-javascript-that-could-cost-you-dearly-in-a-bug-bounty-program

感谢您抽出

.

.

来阅读本文

点它,分享点赞在看都在这里


文章来源: http://mp.weixin.qq.com/s?__biz=MzAxMjYyMzkwOA==&mid=2247503730&idx=2&sn=8c911346fcc63985cd053bb1f9bf5b88&chksm=9a24295f2319d8a0cd13a9f3b39800214934d907c1352ab77b9a75e8de5d5b80c37dd94eecab&scene=0&xtrack=1#rd
如有侵权请联系:admin#unsafe.sh