Commit Graph

105 Commits

Author SHA1 Message Date
N. Taylor Mullen f9b9dcd79b Transition to netstandard.
- dotnet5.X => netstandard1.y (where y = x-1).
- DNXCore50 => netstandardapp1.5.
- Applied the same changes to ifdefs.
2016-03-01 13:36:35 -08:00
Victor Hurdugaci db2093ec2a Return the error code from build.cmd 2016-02-28 10:12:16 -08:00
Victor Hurdugaci 6e3518dafc Update the build scripts 2016-02-27 12:51:13 -08:00
jacalvar aa8fd48c64 Updated antiforgery ServiceCollectionExtensions 2016-02-26 16:13:10 -08:00
Ryan Nowak 4629148519 [Design] Add antiforgery middleware
This new middleware participates in authentication and acts as a filter
when the request doesn't include a valid CSRF token for a POST.

Any authentication middleware that you want to validate an antiforgery
token should go ahead of this middleware in the pipeline (Cookies,
IISIntegration). This also takes care of automatic auth (Windows) done by
weblistener.

Any authentication middleware that you want to ignore antiforgery should
go after this middleware in the pipeline.

To facilitate this, there are a few changes in the antiforgery API
surface. Namely we can now pass in a principal to validate tokens. You
can't pass in a principal to generate tokens - we expect you to be logged
in at that poing. Also, ValidateRequestAsync(...) now checks the HTTP verb
and won't validate GETs and such.
2016-02-24 15:04:09 -08:00
Doug Bunting 9783a7c42b Update `build.cmd` to match latest template
- aspnet/Universe#347
- `%KOREBUILD_VERSION%` doesn't work without this fix
2016-02-24 12:27:40 -08:00
Doug Bunting 478edc1735 Pool `char`s used for base64url-encoding and -decoding
- #23 part 4
- depends on aspnet/HttpAbstractions@8c120a0

nits:
- correct name of a field in `AntiforgerySerializationContext`
- avoid allocations when returning an `AntiforgerySerializationContext` in (unlikely) case `Stream` is unused
- name literal `int` parameters
2016-02-17 23:17:15 -08:00
Ajay Bhargav Baaskaran c2f4bd0be5 Enabled xml doc generation 2016-02-17 12:12:44 -08:00
ryanbrandenburg a8dbf6a255 * Add logging for other IAntiforgery public methods 2016-02-17 11:57:50 -08:00
Ajay Bhargav Baaskaran 220479c1a1 [Fixes #30] Updated UID generation in DefaultClaimUidExtractor 2016-02-16 10:14:52 -08:00
Ryan Nowak ac107b5371 Make IsRequestValid check HTTP method
This code was popping up everywhere this method is called. Seems bad to
duplicate it. Really what the caller wants to know is 'is the request
valid or a potential CSRF exploit?'. This gets the API closer to that.
2016-02-12 16:52:25 -08:00
Kiran Challa 668b67170f Enable tests to run in donet xunit runner 2016-02-09 21:50:19 -08:00
Doug Bunting c85badcf71 Fix bad merge
- not exactly logging at the right spot in `GetAndStoreTokens()`
- test helpers were creating two separate `ServiceCollections`
 - also didn't compile!
2016-02-09 16:43:01 -08:00
Doug Bunting 73695fc443 Serialize cookie token at most once
- #23 part 3
- `Get[AndStore]Tokens()` would deserialize cookie token from request even if `IsRequestValidAsync()` already had
- `GetAndStoreTokens()` serialized an old (never saved) cookie token once and a new one twice

- refactor serialization from `DefaultAntiforgeryTokenStore` to `DefaultAntiforgery`
 - divide responsibilities and ease overall fix
- above refactoring took `IAntiforgeryContextAccessor` responsibilities along to `DefaultAntiforgery` as well
 - store all tokens in `IAntiforgeryContextAccessor` to avoid repeated (de)serializations
 - remove `AntiforgeryTokenSetInternal`

nits:
- bit more parameter renaming to `httpContext`
- remove argument checks in helper methods
 - did _not_ do a sweep through the repo; just files in this PR
2016-02-09 15:29:04 -08:00
ryanbrandenburg c8a9ecc0c1 * Add logging to Antiforgery 2016-02-09 09:27:51 -08:00
Doug Bunting 08cf13b870 Remove `ValidateTokens()` from `IAntiforgery`
- `IAntiforgery` does not expose a way to get an invalid `AntiforgeryTokenSet`
2016-02-05 12:16:10 -08:00
Ajay Bhargav Baaskaran 9445574aa1 Updated Json.Net version 2016-02-04 16:04:44 -08:00
John Luo 57dad8df8c Merge branch 'dev' of git://github.com/hishamco/Antiforgery into hdev 2016-02-04 14:59:32 -08:00
Ryan Nowak 33e3001d53 Remove GetHtml
It's being moved to MVC
2016-02-04 11:22:26 -08:00
Ryan Nowak 3a2d09b066 Move exceptions from the store to the facade
My earlier change to add TryValidateRequestAsync didn't go far enough,
because the store will still throw when the tokens aren't present. This
change is to make the store just return null tokens in these cases, and
move the exceptions to DefaultAntiforgery.
2016-02-04 11:11:45 -08:00
Doug Bunting c91f0ee667 Clean up some tests
- avoid mocking `HttpContext`
- change `DefaultAntiforgeryTest` to mock token generators consistently
2016-02-04 10:11:05 -08:00
Hisham Bin Ateya b1df299ec3 Add 'UseServer' 2016-02-04 13:37:04 +03:00
Doug Bunting 705c080d3b Move Antiforgery implementation details to `.Internal`
- leave `IAntiforgery`, `IAntiforgeryAdditionalDataProvider` and related bits behind
2016-02-03 15:39:33 -08:00
Ryan Nowak 48ee352022 Add form and header name to token set 2016-02-03 14:28:25 -08:00
Ryan Nowak 20140c4c15 Adds a IsRequestValidAsync method
Some other misc cleanup
- docs for IAntiforgeryTokenGenerator
- Add HttpContext parameter where to all IAntiforgeryGenerator methods
- rename parameters on DefaultAntiforgery
2016-02-03 08:08:30 -08:00
Doug Bunting 0ddfa5f0d8 Pool `MemoryStream`, `BinaryReader`, `BinaryWriter`, and `SHA256` instances
- #23 part 2
- reduce `byte[]` and `char[]` allocations because all have internal buffers
 - fortunately, only `MemoryStream` has an unbounded buffer
2016-02-02 16:56:11 -08:00
Ryan Nowak 96063e2476 Remove dependency on routing in sample
Removing the routing dependency since this is moving lower in the stack.
2016-02-02 09:24:29 -08:00
Doug Bunting 492c0798b1 Anything but `HtmlContentBuilder`
- #23 part 1
2016-02-02 08:51:02 -08:00
Doug Bunting 7c7a4a905e Correct project dependencies
- use latest `System.Net.Http`, not hard-coded version
- add imports for the latest CLI
 - see aspnet/FileSystem@4a9a0fd for the inspiration
2016-02-01 18:53:40 -08:00
N. Taylor Mullen 9c9543dde4 Rename AspNet 5 file contents.
See https://github.com/aspnet/Announcements/issues/144 for more information.
2016-01-22 12:24:22 -08:00
N. Taylor Mullen bc0d5528a3 Rename AspNet 5 folders and files.
See https://github.com/aspnet/Announcements/issues/144 for more information.
2016-01-22 12:24:19 -08:00
John Luo 115e89d6f8 Reacting to hosting rename 2016-01-17 17:08:20 -08:00
Victor Hurdugaci 9e032102f6 Build with dotnet 2016-01-15 15:53:26 -08:00
John Luo 807cd77307 Reacting to Hosting API changes 2016-01-12 16:03:24 -08:00
Ajay Bhargav Baaskaran 80fa2908bd Throwing custom AntiforgeryException for token validation failure scenarios 2016-01-07 15:12:55 -08:00
ryanbrandenburg a281b2e369 * Add functional tests for sample 2016-01-06 09:37:15 -08:00
Hao Kung 0eec60b0ac React to OptionsModel => Options 2015-12-21 14:54:54 -08:00
John Luo f49c218bdf Reacting to new Hosting API 2015-12-18 15:24:53 -08:00
Ryan Nowak 1c0996c625 Add a sample demonstrating Antiforgery with AJAX 2015-12-17 13:29:45 -08:00
Ryan Nowak bf6406bc2a PR feedback 2015-12-16 12:48:03 -08:00
Ryan Nowak ea43ce1bb7 update gitignore 2015-12-16 12:38:21 -08:00
Ryan Nowak 3280ff6ac5 Add Header support
This change adds support for retrieving an antiforgery CSRF token via a
configurable header in addition to the form field. This helps with doing
ajax requests in a 1st-party SPA when using cookie auth, and is similar to
functionality provided by a bunch of different frameworks.

In this change there's also a bunch of churn due to avoiding the term
'form' in favor of 'request' and 'session' in favor of 'cookie'. Where
code and error message now mention 'form' they specifically mean
form-encoded content.
2015-12-15 14:18:09 -08:00
Pranav K b69aef3c51 Merge branch 'release' into dev 2015-12-11 12:23:48 -08:00
Pranav K 86795ab1b6 Updating to release NuGet.config. 2015-12-11 12:23:45 -08:00
Pranav K 463e8f9473 React to HtmlAbstractions namespace rename 2015-12-02 10:30:01 -08:00
Pranav K daf16ad184 Enabling CoreCLR tests on Travis 2015-12-01 11:02:49 -08:00
Doug Bunting 6a9b38db77 Return an `IHtmlContent` from `IAntiforgery.GetHtml()`
- part of aspnet/Mvc#3123
- no longer forces caller to wrap the return value in an `HtmlString`

nit: don't HTML encode the word "hidden"
2015-11-25 09:44:54 -08:00
Doug Bunting 78face48d0 Ignore `launchSettings.json` files 2015-11-24 15:31:27 -08:00
Pranav K 130e8f0398 Updating tests to use moq.netcore 2015-11-23 11:39:40 -08:00
Hao Kung e2632d47f0 React to DataProtection changes 2015-11-17 14:08:22 -08:00