New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gorilla_proxy

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gorilla_proxy

  • 0.0.12
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

GorillaProxy

Configurable Rails Engine for proxying API requests to the Gorilla API.

  • Installation
  • Configuration
  • CSRF Protection
  • Routes and Proxying

Installation

Add it to the Gemfile using Gorilla's private gem source:

source 'https://TdrhpteD4VdUEx8DzQgt@gem.fury.io/gorilla/' do
  gem 'gorilla_proxy'
end

Then mount it in the client Rails application:

Rails.application.routes.draw do
  mount GorillaProxy::Engine => '/'
end

Configuration

Setup Application Keys

By default, the proxy will look for the following environment variables:

  • GORILLA_APP_KEY - The application's key
  • GORILLA_APP_SECRET - The application's secret

You should probably just put those values in the ENV, but, if you have to do it manually, you can do so in an initializer:

GorillaProxy.configure do |c|
  c.app_key = 'app-key-which-not-stored-in-the-repo'
  c.app_secret = 'app-secret-which-not-stored-in-the-repo'
end

CSRF Protection

One of the benefits of proxying the API is the added advantage of CSRF protection natively with Rails. Mainting CSRF protected connections is really easy, and there are only a few steps you need to follow.

  1. Initialization - When the user visits the page and we load the client layout, make sure the CSRF token is stored in the typical meta tag attribute in the head.

    <%= csrf_meta_tags %>
    
  2. AJAX Requests and X-CSRF-Token - Take the value of that tag and send it along with any AJAX requests in the X-CSRF-Token header. Rails will handle validating the token.

  3. Caching the new token - Your AJAX request handler should also look for a X-CSRF-Token in the response. Store that new token so it can be re-used in step #2.

Here's an example:

// On Application load
window.csrfToken = $('meta[name="csrf-token"]').attr('content');

// Set an ajax prefilter for the CSRF Token
$.ajaxPrefilter(function(options, originalOptions, xhr) {
  xhr.setRequestHeader('X-CSRF-Token', window.csrfToken);
});

// Set an ajax completion handler on the document
$(document).ajaxComplete(function(event, xhr, settings) {
  var newToken = xhr.getResponseHeader('X-CSRF-Token');
  if (newToken) { window.csrfToken = newToken; }
});

Routes and Proxying

Proxying is handled by directly processing relative endpoints. For example, a call to the app's backend like so:

PUT /api/forms/1
Host: app.gorilla.io

{"name": 'New form name'}

Get's translated into:

PUT /forms/1
Content-Type: application/json
Accept: application/vnd.gorilla.v1+json
Host: api.gorilla.io

{"name": 'New form name'}

The response from the call to the app's backend will mirror the response from Gorilla API exactly.

List of Routes

Proxy RouteApp RouteAuthentication
/api/apps/:pathapi.gorilla.io/apps/:pathApplication Signature
/api/:pathapi.gorilla.io/:pathBearer Token
/auth/loginapi.gorilla.io/apps/tokens/authorizeApplication Signature
/auth/logoutapi.gorilla.io/apps/tokens/revokeApplication Signature
/auth/refreshapi.gorilla.io/apps/tokens/refreshApplication Signature

FAQs

Package last updated on 29 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc