Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to avoid SQL injection in $filter querystring #226

Open
andenis opened this issue Aug 21, 2019 · 7 comments
Open

How to avoid SQL injection in $filter querystring #226

andenis opened this issue Aug 21, 2019 · 7 comments

Comments

@andenis
Copy link

andenis commented Aug 21, 2019

I'm using Breezejs and .Net Framework 4.5
Example:
ExecuteQuery url:
https://XXXXXX/breeze/Breeze/Departments?$filter=**BranchId eq 123L+or+1+eq+1&**$orderby=Name&$expand=Calls

SQL Generated:
WHERE ([Extent2].[CompanyId] = @p_linq0) AND (1 = CAST( [Extent1].[Status] AS int)) AND ([Extent1].[BranchId] = @plinq1 OR @plinq2 = @plinq_3)

SQL Generated parameters:
N'@p_linq0 bigint,@plinq1 bigint,@plinq2 int,@plinq3 int',@plinq0=826,@plinq1=123,@plinq2=1,@plinq_3=1

Thanks!

@andenis andenis changed the title How to avoid SQL injection in $ filter querystring How to avoid SQL injection in $filter querystring Aug 21, 2019
@gmareater
Copy link

gmareater commented Sep 16, 2019

i'm not expert (but good enough) so since it's using parameterized dynamic sql, you could assume it's safe and sql injection would not work

@andenis
Copy link
Author

andenis commented Sep 20, 2019

Ok, thanks your comments @gmareater , but sql injection is possible, only need to change the $filter in the url. I will change to use parameters in my service controller and not continue using the $filter field.

@gmareater
Copy link

attacker might be able change the value in the $filter, but at the end sql server wont execute it

@steveschmitt
Copy link
Member

I think that Entity Framework sanitizes all the parameters and inputs to prevent sql injection, but there may be holes. Do you have an example of an attack that would work?

@andenis
Copy link
Author

andenis commented Sep 25, 2019

changed the $filter parameter, and the Controller return IQueryable (EF Query), but in my .js ExecuteQuery apply filters to this IQueryable.

Parameter: $filter
Attack value: ' , +and+1+eq+1 , +and+1+eq+2 , +or+1+eq+1 , +or+1+eq+2

BreezeFilter

@steveschmitt
Copy link
Member

Yes, it is possible for something in JavaScript to intercept the request and change the URL before it is sent to the server. But this is possible for any HTTP request, and is not specific to $filter nor to Breeze.

Do you have an example where you can inject a sql "DROP TABLE" or "DELETE" command in $filter, and have SQL Server execute it?

@andenis
Copy link
Author

andenis commented Oct 11, 2019

Hi, No inject this commands, but if possible add "AND", "OR" to change the query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants