Click here to Skip to main content
15,888,351 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionUnchecked returned value causing unexpected states and conditions. Pin
Stephen Holdorf10-Jun-15 7:35
Stephen Holdorf10-Jun-15 7:35 
AnswerRe: Unchecked returned value causing unexpected states and conditions. Pin
Richard Deeming10-Jun-15 7:56
mveRichard Deeming10-Jun-15 7:56 
AnswerRe: Unchecked returned value causing unexpected states and conditions. Pin
Sascha Lefèvre10-Jun-15 15:01
professionalSascha Lefèvre10-Jun-15 15:01 
GeneralMessage Closed Pin
11-Jun-15 8:34
Stephen Holdorf11-Jun-15 8:34 
GeneralRe: Unchecked returned value causing unexpected states and conditions. Pin
Richard Deeming11-Jun-15 8:43
mveRichard Deeming11-Jun-15 8:43 
QuestionWeb.config file debug="true" setting Pin
Stephen Holdorf10-Jun-15 3:48
Stephen Holdorf10-Jun-15 3:48 
AnswerRe: Web.config file debug="true" setting Pin
Richard Deeming10-Jun-15 4:02
mveRichard Deeming10-Jun-15 4:02 
QuestionAllowing the attacker to access unathorized records finding. Pin
Stephen Holdorf8-Jun-15 7:00
Stephen Holdorf8-Jun-15 7:00 
I have a scan finding and hope someone can provide any ideas as to best ways to resolve the issue. First I will show the scan Finding then my code and finally what the scanner's recommended solution is.

Finding

Without proper access control, the method GetAttributeKey() in Provider.cs can execute a SQL statement on line 163 that contains an attacker-controlled primary key, thereby allowing the attacker to access unauthorized records.

Rather than relying on the presentation layer to restrict values submitted by the user, access control should be handled by the application and database layers. Under no circumstances should a user be allowed to retrieve or modify a row in the database without the appropriate permissions. Every query that accesses the database should enforce this policy, which can often be accomplished by simply including the current authenticated username as part of the query.

My Code:

Offending line:

myParam.SqlParam.Value = attribute;

Method:


        public string GetAttributeKey(string attribute)
        {
            string qry = "SELECT ws_attribute_key FROM webservice_attributes WHERE ws_attribute = @attribute";

            QueryContainer Instance = new QueryContainer(qry);

            MyParam myParam = new MyParam();

            myParam.SqlParam = new SqlParameter("@attribute", Instance.AddParameterType(_DbTypes._string));

            myParam.SqlParam.Value = attribute;

            Instance.parameterList.Add(myParam);

            object key = ExecuteScaler(Instance);

            return Convert.ToString(key);
        }
<pre>

Scanner's Recommend fix:

<pre>
string user = ctx.getAuthenticatedUserName();
int16 id = System.Convert.ToInt16(invoiceID.Text);
SqlCommand query = new SqlCommand(
            "SELECT * FROM invoices WHERE id = <a href="http://www.codeproject.com/Members/id">@id</a> AND user = <a href="http://www.codeproject.com/Members/user">@user</a>", conn);
query.Parameters.AddWithValue("@id", id);
query.Parameters.AddWithValue("@user", user);
SqlDataReader objReader = query.ExecuteReader();
<pre>


modified 8-Jun-15 14:07pm.

AnswerMessage Closed Pin
8-Jun-15 8:52
Stephen Holdorf8-Jun-15 8:52 
GeneralRe: Allowing the attacker to access unathorized records finding. Pin
Stephen Holdorf8-Jun-15 10:02
Stephen Holdorf8-Jun-15 10:02 
QuestionChosing the best technology Pin
rcanales7-Jun-15 21:23
rcanales7-Jun-15 21:23 
AnswerRe: Chosing the best technology Pin
Afzaal Ahmad Zeeshan8-Jun-15 1:42
professionalAfzaal Ahmad Zeeshan8-Jun-15 1:42 
QuestionGet Image on HTML on the fly from ASP.NET ASPX source not working Pin
DavidMills026-Jun-15 4:28
DavidMills026-Jun-15 4:28 
AnswerRe: Get Image on HTML on the fly from ASP.NET ASPX source not working Pin
F-ES Sitecore6-Jun-15 14:41
professionalF-ES Sitecore6-Jun-15 14:41 
SuggestionRe: Get Image on HTML on the fly from ASP.NET ASPX source not working Pin
Richard Deeming7-Jun-15 21:58
mveRichard Deeming7-Jun-15 21:58 
SuggestionRe: Get Image on HTML on the fly from ASP.NET ASPX source not working Pin
Kornfeld Eliyahu Peter8-Jun-15 0:51
professionalKornfeld Eliyahu Peter8-Jun-15 0:51 
QuestionEval_Bind Pin
Member 111616255-Jun-15 20:08
Member 111616255-Jun-15 20:08 
AnswerRe: Eval_Bind Pin
Richard MacCutchan5-Jun-15 21:28
mveRichard MacCutchan5-Jun-15 21:28 
AnswerRe: Eval_Bind Pin
Richard Deeming7-Jun-15 21:50
mveRichard Deeming7-Jun-15 21:50 
AnswerRe: Eval_Bind Pin
anandkannan858-Jun-15 12:54
anandkannan858-Jun-15 12:54 
AnswerRe: Eval_Bind Pin
User 418025410-Jul-15 11:10
User 418025410-Jul-15 11:10 
AnswerRe: Eval_Bind Pin
wikizhao22-Jul-15 17:17
wikizhao22-Jul-15 17:17 
QuestionHow do I hide some operation contract methods for particular user in WCF? Pin
Manikandan Pandurangan4-Jun-15 1:46
professionalManikandan Pandurangan4-Jun-15 1:46 
SuggestionRe: How do I hide some operation contract methods for particular user in WCF? Pin
Richard Deeming4-Jun-15 2:09
mveRichard Deeming4-Jun-15 2:09 
GeneralRe: How do I hide some operation contract methods for particular user in WCF? Pin
F-ES Sitecore4-Jun-15 21:25
professionalF-ES Sitecore4-Jun-15 21:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.