Ruthie  Bugala

Ruthie Bugala

1619631300

Practical Azure: Secure a .NET Core Web API using Azure AD B2C.

The objective of this post is to understand how to secure a .NET Core web API using Azure AD B2C, and how to access that API from an Angular application.

#net-core #azure-ad-b2c #azure #angular #azure-active-directory

What is GEEK

Buddha Community

Practical Azure: Secure a .NET Core Web API using Azure AD B2C.
Einar  Hintz

Einar Hintz

1602560783

jQuery Ajax CRUD in ASP.NET Core MVC with Modal Popup

In this article, we’ll discuss how to use jQuery Ajax for ASP.NET Core MVC CRUD Operations using Bootstrap Modal. With jQuery Ajax, we can make HTTP request to controller action methods without reloading the entire page, like a single page application.

To demonstrate CRUD operations – insert, update, delete and retrieve, the project will be dealing with details of a normal bank transaction. GitHub repository for this demo project : https://bit.ly/33KTJAu.

Sub-topics discussed :

  • Form design for insert and update operation.
  • Display forms in modal popup dialog.
  • Form post using jQuery Ajax.
  • Implement MVC CRUD operations with jQuery Ajax.
  • Loading spinner in .NET Core MVC.
  • Prevent direct access to MVC action method.

Create ASP.NET Core MVC Project

In Visual Studio 2019, Go to File > New > Project (Ctrl + Shift + N).

From new project window, Select Asp.Net Core Web Application_._

Image showing how to create ASP.NET Core Web API project in Visual Studio.

Once you provide the project name and location. Select Web Application(Model-View-Controller) and uncheck HTTPS Configuration. Above steps will create a brand new ASP.NET Core MVC project.

Showing project template selection for .NET Core MVC.

Setup a Database

Let’s create a database for this application using Entity Framework Core. For that we’ve to install corresponding NuGet Packages. Right click on project from solution explorer, select Manage NuGet Packages_,_ From browse tab, install following 3 packages.

Showing list of NuGet Packages for Entity Framework Core

Now let’s define DB model class file – /Models/TransactionModel.cs.

public class TransactionModel
{
    [Key]
    public int TransactionId { get; set; }

    [Column(TypeName ="nvarchar(12)")]
    [DisplayName("Account Number")]
    [Required(ErrorMessage ="This Field is required.")]
    [MaxLength(12,ErrorMessage ="Maximum 12 characters only")]
    public string AccountNumber { get; set; }

    [Column(TypeName ="nvarchar(100)")]
    [DisplayName("Beneficiary Name")]
    [Required(ErrorMessage = "This Field is required.")]
    public string BeneficiaryName { get; set; }

    [Column(TypeName ="nvarchar(100)")]
    [DisplayName("Bank Name")]
    [Required(ErrorMessage = "This Field is required.")]
    public string BankName { get; set; }

    [Column(TypeName ="nvarchar(11)")]
    [DisplayName("SWIFT Code")]
    [Required(ErrorMessage = "This Field is required.")]
    [MaxLength(11)]
    public string SWIFTCode { get; set; }

    [DisplayName("Amount")]
    [Required(ErrorMessage = "This Field is required.")]
    public int Amount { get; set; }

    [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
    public DateTime Date { get; set; }
}

C#Copy

Here we’ve defined model properties for the transaction with proper validation. Now let’s define  DbContextclass for EF Core.

#asp.net core article #asp.net core #add loading spinner in asp.net core #asp.net core crud without reloading #asp.net core jquery ajax form #asp.net core modal dialog #asp.net core mvc crud using jquery ajax #asp.net core mvc with jquery and ajax #asp.net core popup window #bootstrap modal popup in asp.net core mvc. bootstrap modal popup in asp.net core #delete and viewall in asp.net core #jquery ajax - insert #jquery ajax form post #modal popup dialog in asp.net core #no direct access action method #update #validation in modal popup

Ruthie  Bugala

Ruthie Bugala

1619631300

Practical Azure: Secure a .NET Core Web API using Azure AD B2C.

The objective of this post is to understand how to secure a .NET Core web API using Azure AD B2C, and how to access that API from an Angular application.

#net-core #azure-ad-b2c #azure #angular #azure-active-directory

Top 10 API Security Threats Every API Team Should Know

As more and more data is exposed via APIs either as API-first companies or for the explosion of single page apps/JAMStack, API security can no longer be an afterthought. The hard part about APIs is that it provides direct access to large amounts of data while bypassing browser precautions. Instead of worrying about SQL injection and XSS issues, you should be concerned about the bad actor who was able to paginate through all your customer records and their data.

Typical prevention mechanisms like Captchas and browser fingerprinting won’t work since APIs by design need to handle a very large number of API accesses even by a single customer. So where do you start? The first thing is to put yourself in the shoes of a hacker and then instrument your APIs to detect and block common attacks along with unknown unknowns for zero-day exploits. Some of these are on the OWASP Security API list, but not all.

Insecure pagination and resource limits

Most APIs provide access to resources that are lists of entities such as /users or /widgets. A client such as a browser would typically filter and paginate through this list to limit the number items returned to a client like so:

First Call: GET /items?skip=0&take=10 
Second Call: GET /items?skip=10&take=10

However, if that entity has any PII or other information, then a hacker could scrape that endpoint to get a dump of all entities in your database. This could be most dangerous if those entities accidently exposed PII or other sensitive information, but could also be dangerous in providing competitors or others with adoption and usage stats for your business or provide scammers with a way to get large email lists. See how Venmo data was scraped

A naive protection mechanism would be to check the take count and throw an error if greater than 100 or 1000. The problem with this is two-fold:

  1. For data APIs, legitimate customers may need to fetch and sync a large number of records such as via cron jobs. Artificially small pagination limits can force your API to be very chatty decreasing overall throughput. Max limits are to ensure memory and scalability requirements are met (and prevent certain DDoS attacks), not to guarantee security.
  2. This offers zero protection to a hacker that writes a simple script that sleeps a random delay between repeated accesses.
skip = 0
while True:    response = requests.post('https://api.acmeinc.com/widgets?take=10&skip=' + skip),                      headers={'Authorization': 'Bearer' + ' ' + sys.argv[1]})    print("Fetched 10 items")    sleep(randint(100,1000))    skip += 10

How to secure against pagination attacks

To secure against pagination attacks, you should track how many items of a single resource are accessed within a certain time period for each user or API key rather than just at the request level. By tracking API resource access at the user level, you can block a user or API key once they hit a threshold such as “touched 1,000,000 items in a one hour period”. This is dependent on your API use case and can even be dependent on their subscription with you. Like a Captcha, this can slow down the speed that a hacker can exploit your API, like a Captcha if they have to create a new user account manually to create a new API key.

Insecure API key generation

Most APIs are protected by some sort of API key or JWT (JSON Web Token). This provides a natural way to track and protect your API as API security tools can detect abnormal API behavior and block access to an API key automatically. However, hackers will want to outsmart these mechanisms by generating and using a large pool of API keys from a large number of users just like a web hacker would use a large pool of IP addresses to circumvent DDoS protection.

How to secure against API key pools

The easiest way to secure against these types of attacks is by requiring a human to sign up for your service and generate API keys. Bot traffic can be prevented with things like Captcha and 2-Factor Authentication. Unless there is a legitimate business case, new users who sign up for your service should not have the ability to generate API keys programmatically. Instead, only trusted customers should have the ability to generate API keys programmatically. Go one step further and ensure any anomaly detection for abnormal behavior is done at the user and account level, not just for each API key.

Accidental key exposure

APIs are used in a way that increases the probability credentials are leaked:

  1. APIs are expected to be accessed over indefinite time periods, which increases the probability that a hacker obtains a valid API key that’s not expired. You save that API key in a server environment variable and forget about it. This is a drastic contrast to a user logging into an interactive website where the session expires after a short duration.
  2. The consumer of an API has direct access to the credentials such as when debugging via Postman or CURL. It only takes a single developer to accidently copy/pastes the CURL command containing the API key into a public forum like in GitHub Issues or Stack Overflow.
  3. API keys are usually bearer tokens without requiring any other identifying information. APIs cannot leverage things like one-time use tokens or 2-factor authentication.

If a key is exposed due to user error, one may think you as the API provider has any blame. However, security is all about reducing surface area and risk. Treat your customer data as if it’s your own and help them by adding guards that prevent accidental key exposure.

How to prevent accidental key exposure

The easiest way to prevent key exposure is by leveraging two tokens rather than one. A refresh token is stored as an environment variable and can only be used to generate short lived access tokens. Unlike the refresh token, these short lived tokens can access the resources, but are time limited such as in hours or days.

The customer will store the refresh token with other API keys. Then your SDK will generate access tokens on SDK init or when the last access token expires. If a CURL command gets pasted into a GitHub issue, then a hacker would need to use it within hours reducing the attack vector (unless it was the actual refresh token which is low probability)

Exposure to DDoS attacks

APIs open up entirely new business models where customers can access your API platform programmatically. However, this can make DDoS protection tricky. Most DDoS protection is designed to absorb and reject a large number of requests from bad actors during DDoS attacks but still need to let the good ones through. This requires fingerprinting the HTTP requests to check against what looks like bot traffic. This is much harder for API products as all traffic looks like bot traffic and is not coming from a browser where things like cookies are present.

Stopping DDoS attacks

The magical part about APIs is almost every access requires an API Key. If a request doesn’t have an API key, you can automatically reject it which is lightweight on your servers (Ensure authentication is short circuited very early before later middleware like request JSON parsing). So then how do you handle authenticated requests? The easiest is to leverage rate limit counters for each API key such as to handle X requests per minute and reject those above the threshold with a 429 HTTP response. There are a variety of algorithms to do this such as leaky bucket and fixed window counters.

Incorrect server security

APIs are no different than web servers when it comes to good server hygiene. Data can be leaked due to misconfigured SSL certificate or allowing non-HTTPS traffic. For modern applications, there is very little reason to accept non-HTTPS requests, but a customer could mistakenly issue a non HTTP request from their application or CURL exposing the API key. APIs do not have the protection of a browser so things like HSTS or redirect to HTTPS offer no protection.

How to ensure proper SSL

Test your SSL implementation over at Qualys SSL Test or similar tool. You should also block all non-HTTP requests which can be done within your load balancer. You should also remove any HTTP headers scrub any error messages that leak implementation details. If your API is used only by your own apps or can only be accessed server-side, then review Authoritative guide to Cross-Origin Resource Sharing for REST APIs

Incorrect caching headers

APIs provide access to dynamic data that’s scoped to each API key. Any caching implementation should have the ability to scope to an API key to prevent cross-pollution. Even if you don’t cache anything in your infrastructure, you could expose your customers to security holes. If a customer with a proxy server was using multiple API keys such as one for development and one for production, then they could see cross-pollinated data.

#api management #api security #api best practices #api providers #security analytics #api management policies #api access tokens #api access #api security risks #api access keys

Ruthie  Bugala

Ruthie Bugala

1619605540

Using Azure AD groups authorization in ASP.NET Core for an Azure Blob Storage

This post show how Azure AD groups could be used to implement authorization for an Azure Blob storage and used in an ASP.NET Core Razor page application to authorize the identities. The groups are assigned the roles in the Azure Storage. Azure AD users are added to the Azure AD groups and inherit the group roles. The group ID is added to the claims of the tokens which can be used for authorization in the client application.

#.net #.net core #asp.net core #azure #oauth2 #security #azure ad

Andre  Fisher

Andre Fisher

1626394980

Securing Web API using JWT|WEB API CRUD|Use Swagger|Use Token in .NET Core MVC Application

Creating a JWT Authentication Web API. How to use Token in ASP.NET Core MVC Application.
✔ Test API using SWAGGER & Postman.
✔ How to pass Bearer Token using Swagger.
✔ Complete Web API CRUD.
✔ Call Web API from ASP.NET Core MVC Controller.
✔ Keep token in Session.

✅ Download Source Code: https://payhip.com/b/2XfI

0:00 | Create Web API CRUD Using EF Core
8:23 | How to use Swagger
14:01 | How to use JWT
30:54 | Pass Bearer token using Swagger
32:53 | Test API using Postman
34:27 | Login Demo, Calling API from MVC Controller & use Token

👉FOLLOW US:
On Facebook: https://www.facebook.com/ashproghelp
On Blog: http://ashproghelp.blogspot.com

👉ASP.NET Core Tutorial Playlist:

https://www.youtube.com/playlist?list=PLprnOV9ZLFnscrKZoHtAJvl1hsP_rpyIH

👉ASP.NET Core WEB API Playlist:

https://www.youtube.com/playlist?list=PLprnOV9ZLFnsR9fB624xD8uk0tIOyByl4

👉Blazor Tutorial Playlist:

https://www.youtube.com/playlist?list=PLprnOV9ZLFnt_W3qsBAgxvwgQ4NBNJmvx

👉ASP.NET Core Authentication Playlist:

https://www.youtube.com/playlist?list=PLprnOV9ZLFnv0ZYY0bJT2LMukEN634fiD

👉SignalR Tutorials Playlist:

https://www.youtube.com/playlist?list=PLprnOV9ZLFnuKYOOXw_NE9RM5UcPmM-yp

👉KENDO UI Tutorials (WEB DEVELOPMENT) Playlist:

https://www.youtube.com/playlist?list=PLprnOV9ZLFns32TRnvTr7FgrPQH8kMog6

👉KENDO UI in ASP.NET Core Playlist:

https://www.youtube.com/playlist?list=PLprnOV9ZLFnsoYCrjDuNmWxmWm5WRBXY1

👉Files or Image Upload Playlist:

https://www.youtube.com/playlist?list=PLprnOV9ZLFnsFxlwKs-tOs13kqpakWI9e

👉==========AMCHARTS GRAPH JQUERY PLAYLIST==========
https://www.youtube.com/playlist?list=PLprnOV9ZLFnsGDKm_5W__HErKwGl3H1wu

👉=================RDLC Report PlayList===============
https://www.youtube.com/playlist?list=PLprnOV9ZLFnswiKegU95eTyu7nc_YSZmT

👉=================RDLC PRINT===============
How to print without showing report viewer in RDLC report - C#
https://www.youtube.com/watch?v=uTzwk6zBdQs

👉=================RDLC & Crystal Report===============
https://www.youtube.com/playlist?list=PLprnOV9ZLFnsTnvqGApmsCJqdOi15MVdE

👉=================SQL Server Tutorials (Series)===============
https://www.youtube.com/playlist?list=PLprnOV9ZLFntdSaPFBcMMc89XnH8gfRNy

👉=========TEAM FOUNDATION SERVER=============
TFS source control for beginners:
https://www.youtube.com/watch?v=AjhNxCUTEio

👉==========ANDROID APP DEVELOPMENT============
Quick Learn Android full basic in 45 minutes:
https://www.youtube.com/playlist?list=PLprnOV9ZLFntpdZb7cMvpHGE4YBzPDZJY

👉=================C# Basic=============================
https://www.youtube.com/playlist?list=PLprnOV9ZLFnvpVNZT6WFJeUAuVBNny9Pp

#JWTAuthentication #WebAPICrud #Swagger #UseJWTToken

#web api #jwt #web api #swagger #.net core mvc #.net core