fxnn / gone

KISS wiki engine. Edits any text file. Written in Go.
MIT License
17 stars 5 forks source link

Add extension points #29

Open fxnn opened 8 years ago

fxnn commented 8 years ago

I want to make gone an application that fits many purposes, yet as simple as possible. Therefore, we need extension points (Open Closed Principle). This could include the possibility to call completely new functionality from the UI. Such a concept would greatly complement with the customizeable UI templates.

Stories

  1. An administrator wants to incorporate version control into his gone installation. Now, without modifying the gone sourcecode, he makes gone execute git commit -a everytime a file is saved.
  2. An administrator wants to offer every user of his gone installation the function of publishing all files inside the content root onto a public web server. Therefore, he modifies the UI templates, adding a special link. That link points to a URL which makes gone call a script that publishes the files. The gone sourcecode wasn't changed for this.
  3. An administrator wants to offer a function where each user can see the VCS history of the current resource. Therefore, he modifies the UI templates, adding a special link. That link adds something to the resources URL, which makes gone call a script. That script writes the VCS history to stdout, being displayed by gone. The gone sourcecode wasn't changed for this.
fxnn commented 8 years ago

Implementation via hook directories

Adding functionality to existing workflows calls for hooks. A hook is an executable, e.g. a shell script, placed inside a special directory structure inside the .gone directory (cf. #27). It is executed instead of gones regular request processing, receiving some information about the HTTP request via commandline / environment variables, and having it's output sent back as HTTP response.

Hook types

gone will provide different types of hooks, which differ in the kind of activation criteria.

Depending on the hook's type, you would define them in different directories: .gone/hook-by-action, .gone/hook-by-extension or .gone/hook-by-mime. Below, you can place the executables (or symlinks to executables), possibly in subdirectories. However, naming and exact placement of the executable has an impact of when it gets called.

Hooks vs. CGI

CGI scripts are invoked directly by giving their path and name as HTTP request URL, e.g. http://example.com/cgi-bin/some-cgi-script.pl. This makes file system internas publicy available and has a high risk of misconfiguration. For example, a common problem with CGI scripts is that attackers manage to download the script's sourcecode, thus being able to find security holes.

gones hooks are strictly separated from the content root. The contents of the hook directory will never be modified by gone, nor will they be displayed to a client. gone will only execute hooks that were explicitly defined to be executed in a special situation, they can not be executed by file name.

Potential attack vectors

The following new attack vectors arise. Besides, I sketch potential risk mitigation strategies.

Overwriting the login hook

It's unclear to me whether we should allow overwriting the login hook. The only possible scenario I can imagine is deactivating gones user and permission management, and possibly redirecting login requests to a different application instead.

I can't see, why we should forbid this kind of action.

Access control

In other words, a script that's executable by the gone process, but not world executable will only get invoked in course of the action of a user being logged in.

Output filtering

At the beginning, it will not be possible for a hook to tell gone to render it's output using a template, or using the Markdown parser. A hook's output will directly be used as HTTP body.

Exit codes

If a hook returns a non-zero exit code, by default, gone will deliver a HTTP 500 without any further information about the hook or it's output. However, relevant information will be logged.