c# - Why not reveal the type and identity of the source to the client? -
on page 220, c# language specification version 5.0 says:
it important ... ensure result of query expression never source object itself, reveal type , identity of source client of query.
why problematic reveal type , identity of source client of query?
as example, query expression of form from c in customers select c
translates customers.select(c => c)
instead of customers
.
in above case, seems me returning customers
client returning results of customers.select(c => c)
. why isn't it?
though robert mckee's answer plausible , raises interesting point, not primary issue had in mind when writing section of specification. issue had in mind this:
class c { private list<int> mylist = new list<int>(); // code in c can add items list. public ienumerable<int> items { { return item in mylist select item; } } }
suppose have c
in hand. should able write code?
((list<int>)c.items).add(123);
the existence of query on list should not grant code obtains query ability change list! should grant code right execute query , no more.
now imagine instead of list<int>
, query wrapping database call. if caller can obtain underlying database query perhaps can make queries or edits database author of query did not intend them make.
of course, linq not designed security system, , if line of defense against code wants attack database, you're pretty vulnerable. security systems work better when components use "defense in depth". not ever leaking collection query querying part of defensive strategy.
for more on feature, see article on subject:
Comments
Post a Comment