JohnTheCoolingFan / sayless

A link shortening service
MIT License
0 stars 0 forks source link

Sayless

Sayless is a simple link shortening service.

Features

IP recording

This feature is optional. During development GDPR compliance was an explicit requirement. And so, this function is optional and when enabled, requires a retention period to be specified. It's not intended to be used for metrics, although you're not getting stopped from usingit that way by querying the database. The intended use is to check whether each link is malicious and detect spam and abuse. It is assumed that an external service would be taking care of this. Malicious link, spam and/or abuse would result in a strike being recorded for the IP that created the link. I am still not sure if only the hash of the IP should be recorded instead of plain IP. An excessive amount of strikes recorded on single IP address would result in this IP being blocked from creating new links.

Token authorization system

This feature is optional. Tokens provide a way to limit link creation and data access. A token is a 44-character-long string that uses characters from base58 set. This results in 58^7 possible tokens, a bit over 256-bit security. Each token has an expidation date. By default it is set to be 1 year away from creation time and no easy API for changing it is implemented yet but it is planned. Each token has this list of permissions (subject to change):

For security and ease of setup, a master token must be provided via MASTER_TOKEN environment variable if token system is enabled. It grants access to all functions of the service and cannot be disabled or removed. It can be a string of any length. Character set is limited to what can be used in a header value.

Authorization is performed via "Authorization: Bearer" header.

API description

Request type is GET unless specified otherwise.

/l/:id

Redirects to the link with this id. Uses response code 303 and the link is in Location header.

/l/create

Request type: POST. Accepts the link via request body. Returns 201 code on success and the shortened link in the form /l/:id via Location header. Optionally takes an Authorization Bearer token if link creation only by authorized users is configured

/l/:id/info

Gets information about a link with this id. The returned information is located in the response body as JSON:

/l/tokens/create

Request type: POST. Only available if token system is enabled. Creates a token with specified permissions. Returns status code 201 on success and the created token in the response body. Token permissions are provided via JSON payload in request body, all values default to false:

Configuration

This service is configured via a config file and environment variables.

Environment variables

dotenvy is used to load envoronment variables from .env file, if it exists. Otherwise, environment variables need to be set via other means.

Configuration file

config.toml is used for service configuration. An example file with default values is provided in the repository.