@faable/faable 4.15.0 → 4.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -95,7 +95,9 @@ class FaableApi {
95
95
  ? 'This Faable API key is invalid or was revoked. Create a new one in the dashboard (project settings → API Keys).'
96
96
  : 'Your Faable session has expired or is invalid. Run `faable login` to sign in again.', { cause: error });
97
97
  expired.status = 401;
98
- expired.code = by_key ? 'apikey_invalid' : 'session_expired';
98
+ expired.code = by_key
99
+ ? 'apikey_invalid'
100
+ : 'session_expired';
99
101
  throw expired;
100
102
  }
101
103
  const serverMessage = res.data?.message || res.statusText || 'Unknown Error';
@@ -157,7 +159,11 @@ class FaableApi {
157
159
  async listProjects(params) {
158
160
  const { q, user_id, ...page } = params;
159
161
  return data(this.client.get(`/project`, {
160
- params: { ...page_params(page), ...(q ? { q } : {}), ...(user_id ? { user_id } : {}) }
162
+ params: {
163
+ ...page_params(page),
164
+ ...(q ? { q } : {}),
165
+ ...(user_id ? { user_id } : {})
166
+ }
161
167
  }));
162
168
  }
163
169
  async getProject(project_id) {
@@ -62,6 +62,21 @@ const add_rule = async (opts) => {
62
62
  }
63
63
  if (json)
64
64
  return waf;
65
+ if (action === 'allow') {
66
+ // The one rule that opens instead of closing: say exactly what it opens.
67
+ log.info(`🔓 ${describe_selector(want)} → reaches your app`);
68
+ log.info(` for ${app_name} (${app_id}), even where Faable blocks it for every app`);
69
+ log.info(` (archives like .zip or .tar.gz, dotfiles, config files).`);
70
+ log.info(``);
71
+ log.info(`Your own block and sink rules still win over it, and certificate checks,`);
72
+ log.info(`/.faable/* and /_next/* are never affected.`);
73
+ log.info(``);
74
+ log.info(`It takes about 20s to reach the edge. Then check it with:`);
75
+ log.info(` curl -s -o /dev/null -w '%{http_code}\\n' https://${app_url}<path>`);
76
+ log.info(``);
77
+ log.info(`Undo: faable deploy waf rm ${undo_args(want)} --action allow -a ${app_id}`);
78
+ return waf;
79
+ }
65
80
  const answer = action === 'deny' ? '403' : '404';
66
81
  log.info(`🛡️ ${describe_selector(want)} → ${answer} at the edge`);
67
82
  log.info(` for ${app_name} (${app_id}).`);
@@ -0,0 +1,58 @@
1
+ import { requireApi } from '../../../api/context.js';
2
+ import { print_json, json_option } from '../../../lib/listing.js';
3
+ import { resolve_app_id } from '../resolve_app_id.js';
4
+ import { add_rule } from './add_rule.js';
5
+
6
+ /**
7
+ * The one WAF rule that opens instead of closing: paths of THIS app that Faable
8
+ * blocks for every app (archives, dotfiles, config files) and that this app
9
+ * really serves — a `.zip` download, say. Path only: a user-agent or query
10
+ * exception could be claimed by anyone sending that header.
11
+ */
12
+ const waf_allow = {
13
+ command: 'allow <pattern>',
14
+ describe: 'Let a path Faable blocks for every app (e.g. *.zip) reach your app',
15
+ builder: yargs => json_option(yargs)
16
+ .positional('pattern', {
17
+ type: 'string',
18
+ demandOption: true,
19
+ description: 'Anchored path regex, e.g. ^/downloads/.*\\.zip$ (quote it in your shell)'
20
+ })
21
+ .option('app', {
22
+ alias: 'a',
23
+ type: 'string',
24
+ description: 'App id, name or slug (defaults to the linked app)'
25
+ })
26
+ .option('description', {
27
+ alias: 'd',
28
+ type: 'string',
29
+ description: 'Why this rule exists (shown in `waf list`)'
30
+ })
31
+ .example("$0 deploy waf allow '^/downloads/.*\\.zip$'", 'Serve the .zip files under /downloads that Faable would otherwise refuse')
32
+ .epilogue('Faable refuses some paths for every app before they reach it — ' +
33
+ 'archives like .zip or .tar.gz, dotfiles, config files — because ' +
34
+ 'scanners request them by the thousand. If your app really serves ' +
35
+ 'one, allow exactly that path. Keep the pattern narrow: your own ' +
36
+ 'block and sink rules still win over it, and it can never cover ' +
37
+ '/.well-known/acme-challenge, /.faable or /_next.')
38
+ .showHelpOnFail(false),
39
+ handler: async (args) => {
40
+ const ctx = await requireApi();
41
+ const app_id = await resolve_app_id(args.app, ctx.appId, ctx.api);
42
+ const app = await ctx.api.getApp(app_id);
43
+ const waf = await add_rule({
44
+ api: ctx.api,
45
+ app_id,
46
+ app_name: app.name,
47
+ app_url: app.url,
48
+ pattern: args.pattern,
49
+ action: 'allow',
50
+ description: args.description,
51
+ json: args.json
52
+ });
53
+ if (args.json)
54
+ print_json(waf);
55
+ }
56
+ };
57
+
58
+ export { waf_allow };
@@ -5,7 +5,9 @@ const action_label = (action) => action === 'sink'
5
5
  ? '403 (blocked at the edge)'
6
6
  : action === 'probe'
7
7
  ? 'answered by Faable, app not woken (uptime monitors)'
8
- : action;
8
+ : action === 'allow'
9
+ ? 'allowed (reaches your app where Faable blocks it for every app)'
10
+ : action;
9
11
  /**
10
12
  * Render the effective WAF of an app.
11
13
  *
@@ -1,3 +1,4 @@
1
+ import { waf_allow } from './allow.js';
1
2
  import { waf_block } from './block.js';
2
3
  import { waf_list } from './list.js';
3
4
  import { waf_rm } from './rm.js';
@@ -10,8 +11,9 @@ const waf = {
10
11
  .command(waf_list)
11
12
  .command(waf_block)
12
13
  .command(waf_sink)
14
+ .command(waf_allow)
13
15
  .command(waf_rm)
14
- .demandCommand(1, 'Specify a waf command: list, block, sink or rm'),
16
+ .demandCommand(1, 'Specify a waf command: list, block, sink, allow or rm'),
15
17
  handler: () => {
16
18
  // Unreachable: demandCommand(1) either routes to a subcommand or fails
17
19
  // through the global .fail() in src/index.ts.
@@ -27,7 +27,7 @@ const waf_rm = {
27
27
  })
28
28
  .option('action', {
29
29
  type: 'string',
30
- choices: ['deny', 'sink'],
30
+ choices: ['deny', 'sink', 'allow'],
31
31
  description: 'Only needed when the same rule exists as both'
32
32
  })
33
33
  .option('app', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faable/faable",
3
- "version": "4.15.0",
3
+ "version": "4.16.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "author": "Marc Pomar <marc@faable.com>",