Secure Code Warrior C# Basic OWASP Web Top 10 2017 3: Sensitive Data Exposure and 4: XXE vulnerabilities
Let's continue with some other very common application weaknesses. This set of levels will focus on 3: Sensitive Data Exposure and 4: XXE vulnerabilities
A3: Sensitive Data Exposure
Insecure Cryptography - Insecure Randomness
Seeding the RNG with DateTime.UtcNow.Ticks
will not provide an output that is random enough. An adversary could easily crack it.
Using BouncyCastle's SecureRandom
provides a cryptographically strong random number generator (RNG). It can have up to 128 bits. In addition, SecureRandom uses random data from your OS (for example, the interval between keystrokes, etc.) and uses that as a seed.
Sensitive Data Storage - Plain Text Storage of Sensitive Information
Confidential user data is encrypted via concatenation with an encryption key. However, the key itself is too simple and is stored directly in the code. An adversary could compromise the application and get hold of the key.
User confidential notes are encrypted using AES. Advanced Encryption Standard (AES), also known as Rijndael, is the successor to DES. AES accepts 128, 192, or 256 bit keys. It has a fixed block size of 128 bits, and it is suitable to be implemented for both software and hardware. AES implemented in combination with GCM mode greatly improves protection against distortion, active man-in-the-middle attacks and Padding Oracle Attacks.
Insufficient Transport Layer Protection - Unprotected Transport of Credentials
The server certificate is not verified and the transfer protocol itself is outdated. An adversary can create a phishing server or use MITM attacks.
The server-provided certificate should be verified, and in case of errors, the connection has to be terminated to prevent phishing. The encryption protocol itself has to be as modern as possible. So, the server certificate validation errors are taken into account before the connection is established, and TLS 1.2 is used. An adversary won't be able to use either a phishing server or MITM attacks to hijack credentials.
A4: XXE vulnerabilities
XML External Entities (XXE) - XML External Entities (XXE)
The XmlReaderSettings
has DtdProcessing set to Parse. Next to that, a nonnull XmlResolver
object will allow parsing of external entities. These settings make the XmlReader
unsafe, and consequently, make the application vulnerable to XXE attacks.
有问题的代码
XmlReader
is safe by default. DtdProcessing
is set to Prohibit and the XmlResolver
is set to null
. Untrusted XML input will not be accepted, and consequently, attackers will not get access to sensitive information in this manner.
正确配置是
XML External Entities (XXE) - XML External Entities (XXE)
XmlReaderSettings
instance is configured to disable these features since their use is not provided. There is no way for an adversary to reveal the server secrets since the XML commands will not be interpreted.XML External Entities (XXE) - XML External Entities (XXE)
System.Xml.XmlReader
configuration is set to disable DtdProcessing
and set XmlResolver
to null. In this way, External as no External Entities will be processed, the application will not be vulnerable to XXE attacks.
作者: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