asp.net mvc - Why can't I allow '*' characters in webapi routes safely? (or, if it can, how?) -
i'm wanting use webapi 2 inside mvc5 project (angularjs, not should make difference) create following types of routes
api/animals/cats => return cats api/animals/dogs => return dogs api/animals/* => return animals (e.g. cats+dogs)
background: did started following;
- from visual studio 2013, new empty mvc application
- in controller folder, right click add new controller, select webapi 2 controller
(apologies if looks information, here in case different project types result in different illegal character checking. )
i want able have users pass in '*' character indicate wildcard, indicating all animals. allow this, using webapi, registered following test route;
config.routes.maphttproute( name: routenames.animals, routetemplate: "api/animals/{animal}", defaults: new { id = routeparameter.optional, controller = "animalsapi" } );
when test this, using postman, receive 400 bad request response
, following error message;
a potentially dangerous request.path value detected client (*).
i've read few related blog posts suggesting character evil because of various reasons, referencing w3.org, however, rfc1738 spec (uniform resource locators 'url') (page3) seems allow use of '*' unescaped. extract below;
...thus, alphanumerics, special characters "$-_.+!*'(),", , reserved characters used reserved purposes may used unencoded within url...
maybe i've misread this? '*' chars appear have w3's blessing, gleefully crash nice clean webapi restful(?) webservice.
i don't syntax of having use queryparams work around problem. following quick (and imho, dirty) fix -> get api/animals/?animal=*
defeats whole purpose of having clean route syntax. question is, why '' evil? i.e. if allow it, via requestpathinvalidcharacters
in web.config
, (only '' char, none of other 'known evil' chars, risking? ) pandora's box of hacking woes exposed to?
update ( after accepted correct answer question defined above, prior last comment below before go bed! amazingly quick , accurate responses.)
a more interesting discussion might have been had, if had proposed following example routes; (wink)
api/animals/{type}/{location}/{sex} ... api/animals/*/london/male => return male animals in london api/animals/cats/*/female => return female cats across locations
thanks all! cheers, a
my question is, why '*' evil? i.e. if allow it, via requestpathinvalidcharacters in web.config
they may have special meaning:
the asterisk ("*", ascii 2a hex) , exclamation mark ("!" , ascii 21 hex) reserved use having special signifiance within specific schemes.
i agree claudio's comment, better option "anything" omit term together.
Comments
Post a Comment