is-github

A small library which checks if the provided IP address belongs to GitHub.

Usage no npm install needed!

<script type="module">
  import isGithub from 'https://cdn.skypack.dev/is-github';
</script>

README

npm version

is-github

A small JavaScript library which checks if the provided IP address belongs to GitHub. Works in Node and the browser.

It uses GitHub's meta endpoint to get the valid IP ranges. The response is cached for the duration GitHub provides in the Cache-Control header.

Usage

$ npm i is-github

or "https://cdn.jsdelivr.net/npm/is-github@1".

import { isGitHub } from 'is-github';

if (await isGitHub('1.2.3.4')) {
  console.log('Request came from GitHub!');
} else {
  console.log('Request was not from GitHub.');
}

Options

It is possible to provide the following options in an object as the second argument:

  • service: The service to check. One of: 'hooks', 'web', 'api', 'git', 'pages', 'importer' (Default: 'hooks')
  • userAgent: The user agent to use for the request to GitHub. This might not work in the browser. (Default: 'is-github')
  • timeout: The timeout in ms. (Default: 5000)

Requirements

The following API's are required when running in the browser.