Is an encrypted JSON API that utilizes cookies for authentication and nonces considered to be secure in general?

Is it possible to create a secure SSL'ed API that authenticates using a session ID within a cookie, includes a nonce as a query parameter, and always responds with a JSON 'Object' response? How effective would this be against XSRF attacks?

The goal of this API is to only be accessible by pages on the same domain, allowing for the exposure of private data like usernames and emails while maintaining simplicity for developers.

Here are some reasons why I believe this approach is secure, but please correct me if I'm mistaken:

  • If a <script> tag from a third-party domain tries to access our site, it won't be able to read the JSON object response. Additionally, all state-changing API calls require non-GET methods to prevent any malicious attempts. The lack of JSONP support is intentional to maintain security.
  • SSL with valid certificates prevents man-in-the-middle attacks targeting cookies.
  • Replay attacks are limited by the use of a nonce to restrict the validity of HTTPS requests over time.
  • XMLHttpRequest cannot make cross-domain requests, preventing unauthorized access to our site.
  • CORS concerns are minimized by not advertising cross-domain support in HTML 5 files.
  • Even if an iframe is embedded on a third-party site, the host site cannot access its data due to restrictions on cross-domain communication.

EDIT: Using a nonce can also protect against cross-domain GET requests (like <script> tags). By requesting a nonce in a 'POST' API call that isn't nonce-protected itself, only XmlHTTPRequest's on the same domain can generate a nonce, making the process developer-friendly without requiring server-side involvement. Simply request a nonce from the API being developed against and use it until receiving a 'bad nonce' response, then repeat the process.

Answer №1

I could only envision one potential threat, which is related to DNS rebinding. As long as your webserver is set up correctly (specifically using a name-based virtual host), you should be adequately protected.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting: JQuery dropdown selection not updating image display

I am trying to create a select menu that changes the car image when a user selects a different model, but for some reason it is not working. Here is what I have tried: <h2 class="model">A6 <img src="images/3.jpg" id="image" width="544" height="2 ...

How can I send a jQuery ajax request with multiple custom headers?

I am facing an issue with my basic ajax request as I am trying to include a custom header using the following code: _auth=1,[my_apikey], Interestingly, when I make the same request using Postman, I receive a valid JSON response. However, when I attempt t ...

Encountered a problem initializing Rangy.js on Internet Explorer

Currently, I am developing an angular application that utilizes textAngular along with rangy-core and rangy-selectionsaverestore. However, I am encountering some errors specifically on the latest version of Internet Explorer: Module 'WrappedSelection ...

What is the best way to retrieve AJAX responses from JSON data that contains multiple sets of information

["12-Feb-2017","06-Feb-2017","5","45","40","Neha shishodia","USD","unit2","phase1","Change Request","Client Approval Awaited"]["07-Feb-2017","04-Feb-2017","6","54","48","Neha shishodia","USD","unit2","phase1","Change Request","Manager Approval Awaited"] T ...

Rotating an SVG shape a full 360 degrees results in no visible change

Currently, I am utilizing d3.js for a project and encountering an issue with rotating an SVG element 360 degrees to achieve a full spin back to its original position. If I rotate the element 3/4 of the way using the following code snippet, it works effect ...

Kik Card - Using Synchronous XMLHttpRequest within the Kik.js Script

Getting ready to create a mobile web app powered by Kik! First step, insert the Kik.js script at the bottom of your HTML page... <!-- add this script to your webpage --> <script src="http://cdn.kik.com/kik/2.3.6/kik.js"></script> Excel ...

Best practice for generating date fields in jsGrid

I am a newcomer to utilizing jsGrid for creating a calendar grid, resembling the one illustrated in this image: https://i.sstatic.net/gU4V9.png The header fields have been set up as follows: var headerFields = [{ name: "name", title: "", type: " ...

Using Angular JS, apply multiple column filters within a table to refine the displayed data

I'm currently working on implementing a filter for multiple columns in a table that is being populated by the ng-repeat directive. <tr ng-repeat="descriptiveField in vm.descriptiveFieldList|filter:{name:vm.searchText}" ng-class-even="'even-bg ...

Listen for a click event on an Unordered List using addEventListener

Struggling to transform a for loop that iterates through an unordered list of hyperlinks and adds an 'onclick' function to each into one using an event listener instead. Unfortunately, I have not been able to create a functional solution. Below ...

I am experiencing difficulty with implementing a page break within the <tr> and <tbody> elements

Below is the code I am working with: {% for item in child.items %} {%set ns.count = ns.count + 1%} <tbody style="page-break-inside: avoid"> <tr style="page-break-inside: avoid"> ...

Create a Discord bot that can assign roles based on information stored in a JSON file

I am looking to manage Reaction Roles on Discord by adding or removing them from a JSON file. When a user interacts with an emoji, I want the corresponding role to be added based on the data stored in the JSON file. Currently, my code functions as intende ...

I'm a bit confused about what I'm doing - constantly running into errors stating "is not a function

I am facing an issue with passing one of my functions down as a prop in my component. When I try to do so, I get an error stating that this.nextScene is not a function. Below is a snippet from my component where the problem occurs: nextScene() { th ...

Building a multilingual website using AngularJS UI-Router

I am currently working on developing a multilingual website using AngularJS. While providing translations in templates seems straightforward, I am facing challenges when it comes to implementing proper multilingual routes using UI-Router. Unfortunately, I ...

How can you efficiently manage Access & Refresh tokens from various Providers?

Imagine I am allowing my users to connect to various social media platforms like Facebook, Instagram, Pinterest, and Twitter in order to use their APIs. As a result, I obtain access tokens for each of these providers. Based on my research, it seems advisa ...

Whenever I run "npm run build-dev" in Webpack with JavaScript, the browser continuously refreshes

I've been working on familiarizing myself with webpack lately. I've managed to convert everything to load modules and plugins, and it's all working fine when I use "npm run build-prod". Even when I use liveServer, the HTML loads properly. Ho ...

The text content is not in alignment with the server-rendered HTML for translation purposes with i18n

I have successfully implemented i18n in my Next.js project. The folder structure for my locales is as follows: public/locales/en/translation.json and public/locales/fr/translation.json The error I am encountering is: Uncaught Error: Text content does n ...

Unable to interpret JSON data using jQuery's parseJSON function

Currently, I am attempting to execute server operations using AJAX jQuery(document).on('click','a.edit', function (e) { var id=$(this).prop('id'); var params="id="+id; $.ajax({ ...

Issue with slim framework PSR failing to identify custom header

Below is the current code snippet I am utilizing: <?php use \Psr\Http\Message\ServerRequestInterface as Request; use \Psr\Http\Message\ResponseInterface as Response; $app = new \Slim\App; function han ...

The output is not being generated by the JSON response data

I am dealing with a JSON data that looks like this: [ { "EmployeePersonal": { "id":"1", "epf_no":"111\/22", "name":"Abcd Efgh", "status":"1", "entry_by":"1" }, ...

Null value arising due to AJAX's asynchronous nature

I am facing an issue with a form that includes a select option displaying various choices. My goal is to retrieve the selected option and display it in a text box. The options are loaded using AJAX from an XML data source. When attempting to grab the sele ...