【发布时间】:2018-07-07 22:22:17
【问题描述】:
以下是获取pdf文件并下载的aspx文件中的c#代码。为了生成 pdf,API 服务器被赋予了一个 html 模板内容。
using (HttpClient client = new HttpClient())
{
var apiUrl = <APIServer> + "/api/GetPdfByteData";
client.BaseAddress = new Uri(apiUrl);
Template template = GetTemplate(); //Body property has got the HTML template
string templateBody = template.Body;//html template
var values = new Dictionary<string, string>();
values.Add("html", templateBody);
var jsonStr = JsonConvert.SerializeObject(values);
var stringContent = new StringContent(jsonStr, Encoding.UTF8, "application/json");
//uses an API service to get the pdf content for the template
var response = client.PostAsync(apiUrl, stringContent).Result; //VERACODE - Basic XSS STARTED here
var pdfContent = response.Content.ReadAsByteArrayAsync().Result;
if (response.IsSuccessStatusCode)
{
Response.ContentType = "application/octet-stream";
Response.Clear();
Response.BinaryWrite(pdfContent);//VERACODE - this line has been highlighted for the XSS ENDED HERE
Response.AddHeader("Content-Length", pdfContent.Length.ToString());
Response.AppendHeader("content-disposition", string.Format("attachment;FileName=\"testfile.pdf\""));
Response.End();
}
}
以下是中等严重性警告。
CWD ID:80 可利用性:中性 类别:不当中和 网页中与脚本相关的 HTML 标签(基本 XSS)
应用程序还为所有响应设置了内容安全策略。
在没有任何安全漏洞的情况下,应该如何安全地处理带有字节数组的 API 响应以进行文件下载?
【问题讨论】:
标签: c# asp.net static-code-analysis veracode