Secure Code Warrior C# Basic OWASP Web Top 10 2017 5: Broken Access Control, 6: Security Misconfiguration and 7: XSS vulnerabilities
Learn the ropes or hone your skills in secure programming here. These challenges will give you an understanding of 5: Broken Access Control, 6: Security Misconfiguration and 7: XSS vulnerabilities
5: Broken Access Control,
Access Control - Missing Function Level Access Control
An incorrect implementation when checking the roles in the user claims will allow a malicious actor to have access without the corresponding authorized role.
Role checking has to be based on an allowed list. The role-based authorization checks if any of the user's roles contains in the allowed roles list. In this case, allowed users will get their access, and the rest won't.
Access Control - Insecure Direct Object Reference
Using a request parameter to allow access to research documents may allow a malicious actor to download unauthorized documents from other users.
不能通过request参数去获取用户id,因为外部传递的数据可能被篡改
Internal application objects should not be directly accessible using request parameters that could be manipulated by an attacker. The application is using the UserId
from the user claim instead of the request parameter to find the research document and check the ownership. In this way, an adversary manipulating the request parameter would not be able to have access to sensitive documents.
Access Control - Insecure Direct Object Reference
When referencing a research file to download it, an incorrect ownership check will allow a malicious user to have access to someone else’s research documents.
It is recommended to implement appropriate checks when referencing a research document for downloading. The application is ensuring user ownership before allowing the download. In this way, a malicious actor will not have access to other users' research files.
6: Security Misconfiguration
Security Misconfiguration - Debug Features Enabled
The application tried to log stack trace data only when the debug mode is enabled and there is a debugger attached. However, an incorrect configuration will cause full stack traces to be logged when running in production (where typically there is no debugger attached).
正确写法
It is not recommended to have debug features enabled in production environments. A configuration flag was added with a default value of false
. The application ensures that if there is a debugger attached and if the debug mode is enabled, only then, the full stack trace will be logged.
Security Misconfiguration - Information Exposure
Returning the full stack trace when an error happens may allow a malicious actor to take advantage of the returned information, which may include internal details of the application, to carry out further attacks.
It is recommended to avoid returning detailed internal information when an exception occurs. The application is returning a generic message without attaching the full stack trace of the error. In this way, no valuable information will be provided to malicious actors.
Information Exposure - Error Details
Displaying full error message details when an exception occurs, may disclose internal application details to malicious actors that would use such information to carry out further attacks.
7: XSS vulnerabilities
Cross-Site Scripting (XSS) - Stored Cross-Site Scripting
Unescaped user input is displayed in the browser. An adversary could insert HTML and alter the appearance of the page, or could execute malicious scripts.
ASP.NET MVC has a built-in protection against Cross-Site Scripting (XSS). However, sometimes HTML must be allowed. This is done via the [AllowHTML]
as an attribute of the property in the model class. To safeguard the application from Stored XSS, the System.Web.Security.AntiXss
library can be used, which contains methods to encode HTML input that needs to be displayed in the browser.
Cross-Site Scripting (XSS) - Stored Cross-Site Scripting
Unescaped user input is displayed in the browser. An adversary could insert HTML and alter the appearance of the page, or could execute malicious scripts.
换成
The DisplayFor()
in the Razor page will provide an output of encoded HTML and will prevent scripts from running. However, malicious scripts can still be embedded in the site.
ASP.NET MVC has a built-in protection against Cross-Site Scripting (XSS). However, sometimes HTML must be allowed. This is done via the [AllowHTML]
as an attribute of the property in the model class. To safeguard the application from Stored XSS, the System.Web.Security.AntiXss
library can be used, which contains methods to encode HTML input that needs to be displayed in the browser.
Cross-Site Scripting (XSS) - Reflected Cross-Site Scripting
The [ValidateInput(false)]
attribute on the controller level explicitly allows HTML elements as input.
The AntiXss
library contains methods to protect the application against XSS attacks. The user input is encoded and displayed in the browser.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2021-10-17 炉石传说 佣兵战纪 宝藏
2021-10-17 炉石传说 佣兵战纪 冬泉谷
2021-10-17 炉石传说 佣兵战纪 任务
2021-10-17 炉石传说 佣兵战纪 赐福
2018-10-17 How to create a List of ValueTuple?
2018-10-17 SET IDENTITY_INSERT 和 DBCC CHECKIDENT
2016-10-17 Setting Margin Properties in code