What mock scripts and Try it can reach
Two parts of APIGit act on behalf of a user inside your network: code-based mock servers run scripts that your users write, and Try it sends requests to addresses that readers choose. This page says what each can reach in the installation as shipped, and what you can change.
Code-based mock servers
A code-based mock server is JavaScript from the repository’s apigit-mock folder. It runs in the mock-worker
container.
What contains a script
- No network. The container’s only network is internal to Docker and shared with the
mockcontainer alone. A script cannot open a connection to the backend, the database, Redis, your network or the internet. Keep themock-workerservice on themockworknetwork only. - One process per mock server. Each mock server has its own process, memory limit (160 MB of heap), temporary directory and saved state; what one script changes in its own process is not seen by another.
- Files. A script can read the worker’s own code, the libraries offered to mock scripts and its own directory, and write only its own directory. It cannot start programs.
- Time. A request has ten seconds; then the process is stopped and the request answers 500. A mock server that has been idle for five minutes is stopped until its next request.
- No secrets. The container’s environment holds no password or token, and a script’s own environment is reduced further.
- The container is read-only, runs without privileges or capabilities, and has memory and process limits.
What does not
- The boundary between two mock servers is a process and file permissions inside one container, not a separate machine. Node.js documents its permission model as a safety net, not as a defence against hostile code. Treat the people who may publish code-based mock servers as people you trust with each other’s mock servers: on your own server they are your colleagues.
- A script can use the processor for its ten seconds, and can fill the container’s temporary space (256 MB, shared), which makes other code-based mock servers fail until it is stopped.
Who may publish a mock server is decided by the repository’s permissions.
Try it
Try it sends a request from the tryit container to the address in the API document, or to one the reader types.
Anyone who can open the application can use it; it asks for no sign-in, as on APIGit Cloud.
What is refused, always: the container’s own loopback addresses, the 0.0.0.0/8 range, and link-local
addresses, which include the metadata services of cloud providers. The check is made on the address the connection
actually goes to, so a host name or a redirect that leads to such an address is refused too, and so is an IPv6
address that carries one of them inside (NAT64, 64:ff9b::/96).
What the container cannot reach: the backend’s internal interface, the database and Redis. They are on another Docker network.
What is open by default: the public internet only. Addresses of private networks are refused until you list
them: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 100.64.0.0/10, 198.18.0.0/15 and fc00::/7. So a reader
of a published document cannot use Try it to reach into the network the server stands in unless you have said which
part of it is meant for that.
To open your own APIs, list them in .env. With a list, only what it names can be called:
# the public internet, the APIs under one domain, and one internal network
APIGIT_TRYIT_ALLOW_HOSTS=@public,.api.example.com,10.20.0.0/16
# only your own APIs, nothing public
APIGIT_TRYIT_ALLOW_HOSTS=.api.example.com
# everything the server can reach (not recommended on a network with internal services)
APIGIT_TRYIT_ALLOW_HOSTS=@public,@private
# refused in addition, whatever the list above says
APIGIT_TRYIT_DENY_CIDRS=10.0.0.0/24,192.168.50.0/24An entry is a host name, a .suffix (every name under it), an address range, @public (every public address) or
@private (every private one). A host name on the list may resolve to a private address. A refusal always wins
over the allow list.
To switch Try it off for the whole server, remove the tryit service and set GITEA__apigit__TRYIT to "false"
for the backend and APIGIT_TRYIT to "false" for web and viewer, in a compose.override.yaml.