Git Product home page Git Product logo

sameorigin's Introduction

@cawfree/sameorigin

๐Ÿค– ๐Ÿงช Masquerade as if you were their own frontend.

sameorigin generalizes the process of Same-Origin-Resource-Crossing, which allows you to work around the domain-based restrictions centralized services use to protect their APIs from third parties.

๐Ÿš€ Getting Started

You can install sameorigin via yarn:

yarn add @cawfree/sameorigin

Next, declare the domain you wish to squat on. In the following example, let's assume I want to bypass the CloudFlare restrictions on the Blur Marketplace:

import {sameorigin} from '@cawfree/sameorigin';

const [axios, {close}] = await sameorigin({
  // Define the website url that has access permissions and generates some requests.
  squatURL: 'https://blur.io/airdrop',
});

const {data} = await axios({
  // Important! You must declare the baseURL of the API you intend
  // to target. This is because it is used to isolate requests you
  // intend to hijack for your own purposes.
  baseURL: 'https://core-api.prod.blur.io/v1',
    
  // GET https://core-api.prod.blur.io/v1/prices
  url: '/prices',
  method: 'get',
});

// Once finished, you'll need to close your client to prevent
// memory leaks.
await close();

Warning

Some interfaces defend against tools like sameorigin by making an analysis of the runtime window. If you find your requests are being rejected, please instantiate sameorigin using headless: false as a workaround.

๐Ÿค” How does it work?

When making a call to sameorigin, we allocate an instance of puppeteer in the background which is used to capture requests and serve as a trusted origin for API requests to originate from.

We make the page available via an express server which manages the life cycle of pages, captures requests which satisfy CloudFlare's protections and dynamically inject them with custom query data.

This process is masked behind the returned axios client. The underlying process of squatting on pages, hijacking requests and returning the data as if it were a conventional fetch request are abstracted away from the caller.

โœŒ๏ธ License

CC0-1.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.