Giter Club home page Giter Club logo

ppx_netblob's Introduction

ppx_netblob

OCaml ppx to include a binary blob from a URL as a string. Writing [%netblob "url"] will replace the string with the result of sending an HTTP GET request to url at compile time. This allows the inclusion of arbitary, possibly compressed, data, without the need to respect OCaml's lexical conventions. It should be noted that ppx_netblob will interpret HTTP 301 responses, following the URL given in the response's Location header, which is a possible security vulnerability (and emitting a warning). I would advise against using this in production code, since I haven't done a huge amount of research into how well cohttp supports HTTPS, so I'm not sure if this is subject to security downgrading attacks.

To build

Requires OCaml 4.02 or above.

Run make in the top directory. Then run make in the examples directory. Now run the quine executable.

To install

Run make install in the top directory once make has been run.

To use

The basic (ill-advised) usage of ppx_netblob involves loading a network resource into a string at compile-time, e.g.

let () =
  print_endline [%netblob "https://goo.gl/nTD9Oc"]

is transformed into:

let () =
  print_endline "Hello, World!"

It should be noted that this sort of usage presents a smorgasbord of potential problems for both security and basic usability, although superficial precautions have been taken to minimize such problems. For instance, compiling the example above would produce the following warning:

WARNING: received response code 301 MOVED PERMANENTLY to "https://gist.githubusercontent.com/chrismamo1/ca3210b8f503ecc3ec5b154ff39fb2b3/raw/0fb8245d996f93a0df1e20f94e7df6403c094f62/hello_world.txt" when requesting resource "https://goo.gl/nTD9Oc", this is probably a security vulnerability.

The more useful feature of ppx_netblob involves building custom HTTP request functions at compile time, e.g.

open Lwt

let () =
  let get_message = [%netblob { runtime = "https://goo.gl/nTD9Oc" }] in
  Lwt_main.run (
    get_message ()
    >>= fun s ->
    Lwt_io.printl s)

in this example, [%netblob { runtime = "https://goo.gl/nTD9Oc" }] is expanded into a decently performant function which handles a few problematic cases. This feature is very incomplete, however, and users of this tool (when and if they start to exist) should not expect it to retain a consistent interface over the next few months.

TODO

  • Allow constraints to be placed on which parameters will be accepted when using the runtime netblob ppx, e.g. [%netblob { runtime = "https://github.com/search" ; parameters = ["utf8"; "q"]}
  • Allow the user to place more security constraints when fetching a string at compile time

ppx_netblob's People

Contributors

aantron avatar chrismamo1 avatar johnwhitington avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

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.