Enabling an application to be reached through two different domains for same-origin AJAX requests

Let's think outside the box for a moment and consider a scenario where I am unable to modify HTTP headers or CORS settings.

This is merely a theoretical question.


Here's the situation:

  • Suppose I have an application hosted on one domain, and I wish to send a POST request from another domain that I also own.
  • Additionally, let's assume that I am restricted from adjusting CORS configurations

So, I can successfully make an ajax request from website.com to app.website.com. However, I have another website, website2.com, which also wants to make an ajax request to app.website.com

If I were to create two CNAME records for app.website.com so that app.website2.com directs to the same application, would it be possible to perform ajax requests from either domain without the need for setting Access-Control headers?

As far as I can see, the main concern would possibly involve an SEO penalty from search engines like Google due to the lack of a canonical URL for app.website.com. Nonetheless, in this thought experiment, it functions solely as an endpoint.

Can anyone shed some light on this situation?

Answer №1

By adhering to the identical hostname limitation (including subdomains), you are able to utilize a CNAME record to enable both domains to direct traffic to the same server.

If your inquiry pertains to the significance of the CNAME's name resolution for CORS, the response is "no, it is not taken into account" allowing you to employ this method.

Answer №2

The Same-Origin Policy evaluates based on the hostname (as a component of the origin), rather than the actual server it is hosted on.

That action is not permitted.

In other words, when utilizing shared hosting, one should not be allowed to access others sharing the same server.

An alternative solution would be to utilize JSONP instead.

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

Using jQuery to handle multiple buttons with the same ID

Is there a way to address the issue of multiple buttons sharing the same id? Currently, when clicking on any button, it only updates the record with id=1. How can this problem be resolved? div id="ShowPrace"> <?php try { $stmt = $pdo->prepare(" ...

Verify whether the element retains the mouseenter event after a specified delay

I recently implemented some blocks with a mouseenter and mouseleave event. <button onMouseEnter={this.MouseEnter}>hover</button> MouseEnter(e) { setTimeout(() => { // Checking if the mouse is still on this element // Pe ...

How to distinguish if a background tab is open using JavaScript or jQuery

Is there a way to determine if a new tab with target set to "_blank" was opened from the current page using JavaScript or jQuery? I want to increment a counter in the original window every time a background tab is opened. For example, if a link is clicked ...

Encountering an issue while attempting to convert a string into JSON from a .json file within a Node.js environment

var jsonObject = collages; file.writeFile('collage.json', JSON.stringify(jsonObject), function(err){ if (err) throw err; console.log('Success'); }); var result = ''; result += file.readFile('collage.json', ...

Error: Unexpected symbol "<" found in JSON at position 4

A JSON syntax error occurred at position 4, causing an Unexpected token < error message. The issue seems to be with the JSON.parse function in the jQuery library. Despite searching online and trying various solutions, I have been unable to resolve this ...

Creating a live data stream to listen for new additions to the database in PHP/CodeIgniter

I have implemented a code using ajax to fetch data from a MySQL database in real-time. Currently, the ajax call retrieves all the data and then loops through each entry to display it. What I am looking for is a way to avoid fetching all the data again and ...

Is it possible to retrieve several columns using the pluck method in Underscore.js following the input from the where method, similar to LINQ

var persons = [ {name : "Alice", location : "paris", amount : 5}, {name : "Bob", location : "tokyo", amount : 3}, {name : "Eve", location : "london", amount : 10} ]; var filteredResults=_.pluck(_.where(persons, {location : "paris"}), 'nam ...

Accessing specific documents in Firebase cloud functions using a wildcard notation

Currently, I am working on implementing Firebase cloud functions and here are the tasks I need to achieve: Monitoring changes in documents within the 'public_posts' collection. Determining if a change involves switching the value of the &ap ...

Video texture incorporated into Three.js

I'm currently experimenting with using a specific section of a video as a texture on a Three.js mesh. The video in question can be found at this link: . It features a fisheye lens, and I am only interested in incorporating the central circular portio ...

Unable to access REST API

I'm currently working on setting up a basic RESTful API with Django Rest Framework and integrating it with AngularJS. Despite following various tutorials and learning about controllers and resources in Angular, I seem to be facing an issue in accessin ...

How to use Ajax to update a Filefield in Django

Looking for a way to update an object's FileField using Ajax? I've created a wav blob in the browser and am trying to pass it by appending it to a FormData instance: var data = new FormData(); data.append('sound', blob); ...

Prevent scrolling on browser resize event

I am working on a basic script that adds a fixed class to a specific div (.filter-target) when the user scrolls beyond a certain point on the page. However, I am wondering how I can prevent the scroll event from triggering if the user resizes their brows ...

Define a property within an object literal that sets a function's property

I am defining a new tasks object: var tasks = { test: () => { /// .... } }; Within the test function, I am attempting to assign a value to the tasks.test.description property. Despite my efforts, such as: var tasks = { test: () ...

Ajax Form Compatibility Issue with Internet Explorer Versions 8 and 9

I have developed a form that utilizes Ajax to ensure the page does not refresh upon submission. The functionality works perfectly in Chrome and Firefox, but I encountered an issue when testing it on Internet Explorer (specifically versions 8 and 9). When a ...

Retrieving data with jSON through the local storage API

Seeking assistance with a problem I'm facing. Being new to this, the textbook Headfirst into programming isn't very helpful in explaining. After researching on stackoverflows, I'm still struggling. Any guidance would be greatly appreciated. ...

What causes the consistent filling of responses in jQuery ajax?

After observing that the response of an ajax call using jQuery is never empty, I have come across the following code snippet: $.ajax({ type: "get", data: { data }, url: "phpFile", datatype: 'text' }).done(functio ...

The radio button functionality is not functioning properly as intended

Having trouble with the current code that utilizes HTML and JavaScript. There is an HTML table on the page with a radio button and 4 other fields. The table is generated dynamically when values are set through the controller. It is also possible to add new ...

Loss of styling is observed with jQuery's html() function

Here is the HTML code I am working with: <div class="myList"> <select> <option value="1">Item1</option> <option value="2">Item2</option> </select> </div> Everything looks great in terms of CS ...

Creating a JavaScript array filled with database data using PHP

Below is a snippet of PHP code used to establish a connection to a database: <?php $host = "localhost"; $user = "admin"; $password = ""; $dbname = "test"; $con = new mysqli($host, $user, $password, $dbname) or die ('Could not connect to the d ...

Transmitting JSON object and JavaScript variable via AJAX communications

I am attempting to send a JSON object and two JavaScript arrays in the same AJAX call. However, I keep encountering the following error: System.ArgumentException: Invalid JSON primitive: object I suspect that this error is related to the different v ...