GithubHelp home page GithubHelp logo

cloudflare / cloudflare-plugin-frontend Goto Github PK

View Code? Open in Web Editor NEW
30.0 22.0 20.0 3.65 MB

A React/Redux front-end for Cloudflare's WordPress, Magento2, and cPanel plugins.

Home Page: https://cloudflare.com

JavaScript 100.00%

cloudflare-plugin-frontend's Introduction

Build using Yarn

  1. yarn install
  2. yarn run build

Development Tasks

$ yarn run build
$ OUTPUT_PATH=custom-path.js yarn run build
$ yarn run build:production
$ yarn run lint
$ yarn run format
$ yarn run test

Production

For production run yarn run build:production to get a minified version of compiled.js

Building Your Own Backend

This repository serves as the front end for all of our 3rd party integrations. It is intended to be backend agnostic with the intention of making it as easy as possible to port it to new backends. If you would like to build a custom backend just follow these steps:

  1. Implement RestProxyCallback()
    /*
     * A callback for cf-util-http to proxy all calls to our backend
     *
     * @param {Object} [opts]
     * @param {String} [opts.method] - GET/POST/PUT/PATCH/DELETE
     * @param {String} [opts.url]
     * @param {Object} [opts.parameters]
     * @param {Object} [opts.headers]
     * @param {Object} [opts.body]
     * @param {Function} [opts.onSuccess]
     * @param {Function} [opts.onError]
     */
     function RestProxyCallback(opts) {}

This method is called on every request before it is sent. It should route all absolute URLs to the endpoint for your backend. Requests with relative URLs for things like localization (./lang/*.js) and config (./config.json) should remain unchanged.

  1. Build your backend data store Your backend needs to store the following information about each user:

  2. In index.html create a variable in local storage called cfEmail which contains Cloudflare Client V4 API Email of the current user.

  3. Build an API Client for the Cloudflare V4 API which adds the necessary headers to each request.

  4. Build an API Client for the Cloudflare Host API which adds the Host Key to all requests.

JSON response for endpoint /config

{
    "debug": false,
    "featureManagerIsFullZoneProvisioningEnabled": false,
    "isDNSPageEnabled": true,
    "isSubdomainCheckEnabled": true,
    "homePageCards": [
        "ApplyDefaultSettingsCard",
        "AutomaticHTTPSRewritesCard",
        "IpRewriteCard",
        "PluginSpecificCacheCard",
        "PluginSpecificCacheTagCard"
    ],
    "moreSettingsCards": {
        "container.moresettings.speed": [
            "AlwaysOnlineCard",
            "BrowserCacheTTLCard",
            "CacheLevelCard",
            "DevelopmentModeCard",
            "IPV6Card",
            "ImageOptimizationCard",
            "MinifyCard",
            "PurgeCacheCard",
        ],
        "container.moresettings.security": [
            "AdvanceDDoSCard",
            "BrowserIntegrityCheckCard",
            "ChallengePassageCard",
            "SecurityLevelCard",
            "SSLCard",
            "WAFCard"
        ]
    },
    "locale": "en",
    "integrationName": "frontend",
    "useHostAPILogin": true,
    "version": "2.8.1"
}

cloudflare-plugin-frontend's People

Contributors

aseure avatar icyapril avatar jacobbednarz avatar jwineman avatar manatarms avatar sejoker avatar thellimist avatar xhmikosr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cloudflare-plugin-frontend's Issues

Using an API Token restricted only to the website's domain, causes a "Forbidden" error in the plugin

We have multiple sites under the same CF account and we would like to use API Tokens to authenticate the Wordpress plugin to prevent a breach in one website to potentially cause drama in other ones.

When we restrict the token to only the zone of the website, the plugin GUI stops working with a "Forbidden" error in the bottom red bar. This defies the benefit of using API Tokens because the API Token for one website can edit any zone in the Cloudflare account.

Steps to recreate:

  1. Create a new API Token
  2. in the "Zone Resources" settings select "Include" - "Specific Zone" - "the domain of your website"
  3. Use the token to authenticate the plugin
  4. When you try to login or edit something in the plugin it will show a "Forbidden" error
  5. If you remove the setting at (2) the plugin is able to login successfully

Upon further investigation, the request that fails is triggered by this function that tries to fetch all the zones in the connected account:

export function asyncFetchZones() {

I tried to do the request manually with the restricted token and the response is:

{
  "success":false,
  "errors":[
      {
       "code":0,
       "message":"Actor 'com.cloudflare.api.token...' requires permission 'com.cloudflare.api.account.zone.list' to list zones"
      }
  ],
  "messages":[],
  "result":null
}

So if we set an API token to only access one zone, it will not have the ability to get the list of available zones. I'm not been able to grant that permission manually.

Can the error be catched and the package will provide a way to enter the zoneID manually?

This issue has been previously open in the wordpress-plugin repository:
cloudflare/Cloudflare-WordPress#255

API key field uses regular text type input

The input field for API key on the login screen uses a regular text type, instead of password.

This dramatically increases the amount of places an API key is exposed.

For example browsers will show the full key as a form suggestion (image is with a revoked key).
Screenshot from 2020-11-04 14-29-04

I don't see a reason to not use a password type field here.

We don't trim user email and api key

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.