MaheshBabu (Community Member) asked a question.

Information leakage issue CWE 201 & 209

The application calls the system_net_http_dll.System.Net.Http.HttpClient.PostAsync() function, which will result in data being transferred out of the application (via the network or another medium)

Code-1

using (var httpClient = new HttpClient())

      {

        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        //-- Attach the id token. Session token will not work for this endpoint, because session token does not have application id claim.

        httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessionToken);

 

        string getApplicationsForUserApiEndPoint = string.Format("{0}{1}?sourceApplicationId={2}", testUrl.TrimEnd('/'), APPLICATIONS_FOR_USER_API_PATH, applicationId);

        httpClient.BaseAddress = new Uri(getApplicationsForUserApiEndPoint.ToString());

        var userApplicationsResponse = await httpClient.GetAsync("");

        if (userApplicationsResponse.IsSuccessStatusCode)

        {

          var userApplicationsResponseContent = await userApplicationsResponse.Content.ReadAsStringAsync();

          if (!string.IsNullOrEmpty(userApplicationsResponseContent))

          {

            userApplicationModelList = JsonConvert.DeserializeObject<List<UserApplicationModel>>(userApplicationsResponseContent);

            if (userApplicationModelList == null || !userApplicationModelList.Any())

            {

              LogManager.TEST.ErrorLogFormat("TESTHelper:GetApplicationsForUser() - TEST did not return any application for Employee Id {0}.", loggedInEmployeeId);

            }

          }

        }

        else

        {

          LogManager.TEST.ErrorLogFormat("TESTHelper:GetApplicationsForUser() - TEST returned a status of '{0}' while trying to get the applications for Employee Id {1}.", userApplicationsResponse.StatusCode, loggedInEmployeeId);

        }

      }

 

Code-2

using (var client = new HttpClient())

        {

          ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

          client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

          ActionTrackerModel actionTrackerModel = new ActionTrackerModel();

          actionTrackerModel.ActionCategory = (int)category;

          actionTrackerModel.EventDateTime = DateTime.UtcNow;

          actionTrackerModel.UserId = UserID;

          actionTrackerModel.Message = LogMessage;

          List<ActionTrackerModel> input = new List<ActionTrackerModel>();

          input.Add(actionTrackerModel);

          _loger.DebugFormat(HttpUtility.HtmlEncode(String.Format("parameters are : ActionCategory = {0} , EventDateTime = {1} , UserId = {2} , Message = {3}", ((int)category).ToString(), DateTime.UtcNow.ToString(), UserID.ToString(), LogMessage.ToString())).Replace("&amp;", "&"));

          var content = new StringContent(JsonConvert.SerializeObject(input), Encoding.UTF8, "application/json");

          string url = ConfigurationManager.AppSettings["HAPLogUrl"].ToString();

          client.BaseAddress = new Uri(url.ToString());

          var httpResponse = client.PostAsync("", content);

          var response = httpResponse.Result;

          _loger.DebugFormat(HttpUtility.HtmlEncode(String.Format("HTTP Response & Response result = {0} and {1}", httpResponse.ToString(), response.ToString())).Replace("&amp;", "&"));

          if (response.StatusCode != HttpStatusCode.OK)

          {

            _loger.Error("Unable to log to Hap portal. Status Code " + response.StatusCode.ToString());

          }

          else

          {

            _loger.Debug("Successfully logged to kenisis and the response code is " + response.StatusCode.ToString());

          }

        }

The issue is this 2 code - var userApplicationsResponse = await httpClient.GetAsync(""); & var httpResponse = client.PostAsync("", content); which is causing the information leakage issue. Kindly let us know about this issue to fix CWE 201 & 209 information leakage ASAP.


  • Hi @MaheshBabu (Community Member)​ ,

     

    Veracode Static Analysis reports flaws of CWE-201: Insertion of Sensitive Information Into Sent Data when it can detect that sensitive data (such as from configuration) is going into outgoing network traffic (for example an email or HTTP request).

    The risk is that if sensitive data is incorrectly used this may lead to leakage of information.

    We recommend verifying:

    • That sensitive data is shared, information from configuration files may not be sensitive in nature. If so document this with a mitigation proposal: https://help.veracode.com/go/improve_mitigation and contact your security team for a review
    • That the functionality does not use sensitive data inappropriately (for example 'debugging emails' containing a lot of sensitive information shared over email). If so we recommend you remove this functionality
    • Ask your security team for requirements and recommendations on use of sensitive data.

     

    Veracode Static Analysis will report CWE - 209 : Information Exposure Through an Error Message if we detect that information from an error message is sent outside of the application.

    In general when reviewing flaws of this category we recommend reviewing the 'Data Path' (in the IDE plugin it is called "Call stack") as it should show the path that our analysis has found where error message contents are added to the variable.

     

    I would recommend you schedule a consultation call to discuss.

    You can check out this knowledge article (https://community.veracode.com/s/article/How-to-schedule-a-consultation-call) on how to schedule a consultation call with us.

     

    Thank you,

    Boy Baukema

    Expand Post

Topics (4)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.