views:

1360

answers:

3

I have code like this:

var newMsg = new Msg
{
    Var1 = var1,
    Var2 = var2
};

using (AppDataContext appDataContext = new AppDataContext(ConnectionString))
{
    appDataContext.CClass.InsertOnSubmit(newMsg);
    appDataContext.SubmitChanges();
}

After reading this post I believe that the same logic applies.

Does anyone think that this is subject to SQL Injection Attack?

+4  A: 

The second answer in the post you're referencing says it:

LINQ to SQL uses *execute_sql* with parameters.

It does not concatenate property values into a one big INSERT ... VALUES('...', '...')

liggett78
I'm not sure that it does... it is just a command that is parameterised. execute_sql is used to do the same from *within* TSQL.
Marc Gravell
User input that is parameterised is safe from injection. Injection attacks only apply when user input is concatenated.
+1  A: 

No, but you should be validating user data anyhow.

Will
+3  A: 

The underlying operation of the DataContext is via the SqlCommand which uses paramatised SQL.

So your insert statement will look like this:

INSERT INTO [MSG] [Var1] = @p1, [Var2] = @p2
Slace