greenlitlab 0.0.0-stage → 0.1.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.
- package/CHANGELOG.md +11 -0
- package/LICENSE +202 -0
- package/README.md +51 -2
- package/SECURITY.md +13 -0
- package/bin/greenlit.mjs +89 -0
- package/package.json +18 -4
- package/server.json +18 -0
- package/src/grade.mjs +346 -0
- package/src/history.mjs +26 -0
- package/src/mcp.mjs +59 -0
- package/src/severity.mjs +2 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (8 November 2026)
|
|
4
|
+
|
|
5
|
+
First release. Greenlit grew out of `crumple site` and is now its own product.
|
|
6
|
+
|
|
7
|
+
- Grades a deployed app A to F: secret keys in its JavaScript, a Supabase service_role key, source maps, security headers.
|
|
8
|
+
- With `--mine`: Supabase tables and Firebase data anyone can read, counted without reading data.
|
|
9
|
+
- Recognises Lovable, Bolt, Replit, Emergent, Base44 and v0, and writes each fix prompt for that builder.
|
|
10
|
+
- Shows what got fixed since the last check.
|
|
11
|
+
- Web check at greenlit.priberry.com, and an MCP server with one tool, `greenlit_check`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,52 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Greenlit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Is your AI-built app safe to launch?** Greenlit grades a deployed app from A to F for what a stranger can use against it. It explains each problem in plain words and gives you a prompt to paste back into Lovable, Bolt, v0, Replit or Emergent that fixes it. Run it again after the fix, and it shows what got fixed.
|
|
4
|
+
|
|
5
|
+
**In the browser:** [greenlit.priberry.com](https://greenlit.priberry.com). Paste your app's address. Nothing to install.
|
|
6
|
+
|
|
7
|
+
**On your computer:**
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx greenlitlab myapp.lovable.app
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## What it checks
|
|
14
|
+
|
|
15
|
+
| Check | Where it runs |
|
|
16
|
+
|---|---|
|
|
17
|
+
| Secret keys (Stripe, OpenAI, AWS, GitHub and more) in the JavaScript every visitor downloads | everywhere |
|
|
18
|
+
| A Supabase `service_role` key in the browser | everywhere |
|
|
19
|
+
| Source maps that hand out your source code | everywhere |
|
|
20
|
+
| Missing security headers (CSP, framing) | everywhere |
|
|
21
|
+
| Supabase tables anyone can read with the public key | your own app, `--mine` |
|
|
22
|
+
| Firebase Realtime Database and Firestore open to everyone | your own app, `--mine` |
|
|
23
|
+
|
|
24
|
+
The database checks ask for a row count (Supabase) or one document name (Firebase), never for data. They run only when you say the app is yours, because testing someone else's database without permission isn't OK.
|
|
25
|
+
|
|
26
|
+
## Commands
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx greenlitlab <url> # grade an app
|
|
30
|
+
npx greenlitlab <url> --mine # your own app: database checks too
|
|
31
|
+
npx greenlitlab <url> --prompt 1 # print fix prompt 1 only (pipe it to pbcopy)
|
|
32
|
+
npx greenlitlab <url> --json # the full result
|
|
33
|
+
npx greenlitlab <url> --fail-on high # exit 1 if anything this serious is found, for CI
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The last result for each app is kept in `~/.greenlit/sites/` (grade, finding ids and titles only, never keys) so the next run can show what changed.
|
|
37
|
+
|
|
38
|
+
## In Claude, Cursor, VS Code and other agents
|
|
39
|
+
|
|
40
|
+
Add Greenlit as an MCP server:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{ "mcpServers": { "greenlit": { "command": "npx", "args": ["-y", "greenlitlab@0.1.0", "mcp"] } } }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Then ask your agent to check the app it just deployed and apply the fixes. The `greenlit_check` tool returns the grade, every finding and its fix prompt.
|
|
47
|
+
|
|
48
|
+
## Made by Priberry
|
|
49
|
+
|
|
50
|
+
Greenlit comes from [Priberry](https://priberry.com), the crash-test lab for AI agents. Its sister tools: [Crumple](https://crumple.priberry.com) crash-tests coding agents, and [Tare](https://tare.priberry.com) shows what they cost.
|
|
51
|
+
|
|
52
|
+
Apache-2.0. Found a problem? [Open an issue](https://github.com/priberry-data/greenlitlab/issues), or see [SECURITY.md](SECURITY.md).
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Security and scanning policy
|
|
2
|
+
|
|
3
|
+
## How Greenlit checks a site
|
|
4
|
+
|
|
5
|
+
- The web check and `npx greenlitlab <url>` read only what the site serves to every visitor: the page and the JavaScript it loads from its own address. They never sign in and never send data to the app.
|
|
6
|
+
- Database checks run only with `--mine`, on the person's own computer, for an app they say is theirs. They ask Supabase for a row count with a `HEAD` request and Firebase for one document name with no fields. They never read rows or documents.
|
|
7
|
+
- The web check never runs database checks, refuses internal addresses, IP addresses and unusual ports, limits each visitor to 20 checks an hour, and caches each result for ten minutes so nobody can use it to hammer a site.
|
|
8
|
+
- When a secret key is found, the web result never shows any part of it.
|
|
9
|
+
- We don't publish grades for other people's apps.
|
|
10
|
+
|
|
11
|
+
## Reporting a vulnerability
|
|
12
|
+
|
|
13
|
+
Please open a private security advisory on GitHub: https://github.com/priberry-data/greenlitlab/security/advisories/new
|
package/bin/greenlit.mjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// greenlit: is your AI-built app safe to launch? A grade from A to F, plain-English reasons, and a prompt
|
|
3
|
+
// to paste back into Lovable, Bolt, v0, Replit or Emergent that fixes each problem.
|
|
4
|
+
// greenlit <url> grade a deployed app from what every visitor can see
|
|
5
|
+
// greenlit <url> --mine also check your own database (counts and names only, never data)
|
|
6
|
+
// greenlit mcp run as an MCP server for Claude, Cursor, VS Code and other agents
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { parseArgs } from "node:util";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { siteScan, compare, renderSite } from "../src/grade.mjs";
|
|
12
|
+
import { SEVERITY } from "../src/severity.mjs";
|
|
13
|
+
import { loadLast, saveRun } from "../src/history.mjs";
|
|
14
|
+
|
|
15
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
16
|
+
const { version: VERSION } = JSON.parse(fs.readFileSync(path.join(ROOT, "package.json"), "utf8"));
|
|
17
|
+
|
|
18
|
+
const HELP = `greenlit ${VERSION}: is your AI-built app safe to launch?
|
|
19
|
+
|
|
20
|
+
npx greenlitlab <url> grade an app from what every visitor can see
|
|
21
|
+
npx greenlitlab <url> --mine your own app: also check which database tables anyone can read
|
|
22
|
+
npx greenlitlab <url> --prompt 1 print just fix prompt 1, to copy (add | pbcopy on a Mac)
|
|
23
|
+
npx greenlitlab <url> --json the full result as JSON
|
|
24
|
+
npx greenlitlab <url> --fail-on high exit 1 if anything this serious is found (for CI)
|
|
25
|
+
npx greenlitlab mcp run as an MCP server
|
|
26
|
+
|
|
27
|
+
Run it again after a fix: it shows what got fixed. In the browser: https://greenlit.priberry.com`;
|
|
28
|
+
|
|
29
|
+
let opt, positionals;
|
|
30
|
+
try {
|
|
31
|
+
({ values: opt, positionals } = parseArgs({
|
|
32
|
+
allowPositionals: true,
|
|
33
|
+
options: {
|
|
34
|
+
mine: { type: "boolean" },
|
|
35
|
+
prompt: { type: "string" },
|
|
36
|
+
json: { type: "boolean" },
|
|
37
|
+
"fail-on": { type: "string" },
|
|
38
|
+
version: { type: "boolean", short: "v" },
|
|
39
|
+
help: { type: "boolean", short: "h" },
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
42
|
+
} catch (e) {
|
|
43
|
+
console.error(`greenlit: ${e.message}\n\n${HELP}`);
|
|
44
|
+
process.exit(2);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (opt.version) {
|
|
48
|
+
console.log(VERSION);
|
|
49
|
+
} else if (opt.help || !positionals[0]) {
|
|
50
|
+
console.log(HELP);
|
|
51
|
+
} else if (positionals[0] === "mcp") {
|
|
52
|
+
const { serve } = await import("../src/mcp.mjs");
|
|
53
|
+
await serve({ version: VERSION });
|
|
54
|
+
} else {
|
|
55
|
+
if (opt["fail-on"] && !(opt["fail-on"] in SEVERITY)) {
|
|
56
|
+
console.error(`greenlit: --fail-on takes ${Object.keys(SEVERITY).join(", ")}`);
|
|
57
|
+
process.exit(2);
|
|
58
|
+
}
|
|
59
|
+
const target = positionals[0];
|
|
60
|
+
const quiet = opt.json || opt.prompt || !process.stderr.isTTY;
|
|
61
|
+
const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
62
|
+
let i = 0;
|
|
63
|
+
const timer = quiet ? null : setInterval(() => process.stderr.write(`\r${frames[i++ % frames.length]} looking at ${target} the way a stranger would`), 80);
|
|
64
|
+
let result;
|
|
65
|
+
try {
|
|
66
|
+
result = await siteScan(target, { mine: opt.mine });
|
|
67
|
+
} catch (e) {
|
|
68
|
+
if (timer) (clearInterval(timer), process.stderr.write("\r\x1b[K"));
|
|
69
|
+
console.error(`greenlit: ${e.message}`);
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
if (timer) (clearInterval(timer), process.stderr.write("\r\x1b[K"));
|
|
73
|
+
|
|
74
|
+
if (opt.prompt) {
|
|
75
|
+
const withPrompt = result.findings.filter((f) => f.prompt);
|
|
76
|
+
const p = withPrompt[Number(opt.prompt) - 1];
|
|
77
|
+
if (!p) {
|
|
78
|
+
console.error(`greenlit: there is no fix prompt ${opt.prompt}; this check has ${withPrompt.length}.`);
|
|
79
|
+
process.exit(2);
|
|
80
|
+
}
|
|
81
|
+
console.log(p.prompt);
|
|
82
|
+
} else {
|
|
83
|
+
const change = compare(loadLast(result.url, result.mine), result);
|
|
84
|
+
saveRun(result);
|
|
85
|
+
if (opt.json) console.log(JSON.stringify({ ...result, change }, null, 2));
|
|
86
|
+
else console.log(renderSite(result, change, { color: Boolean(process.stdout.isTTY && !process.env.NO_COLOR) }));
|
|
87
|
+
}
|
|
88
|
+
if (opt["fail-on"] && result.findings.some((f) => SEVERITY[f.severity] >= SEVERITY[opt["fail-on"]])) process.exitCode = 1;
|
|
89
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "greenlitlab",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Is your AI-built app safe to launch? A grade from A to F for apps built with Lovable, Bolt, v0, Replit or Emergent, with a fix prompt for every problem.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"greenlit": "bin/greenlit.mjs",
|
|
8
|
+
"greenlitlab": "bin/greenlit.mjs"
|
|
9
|
+
},
|
|
10
|
+
"files": ["bin", "src", "README.md", "CHANGELOG.md", "SECURITY.md", "LICENSE", "server.json"],
|
|
11
|
+
"engines": { "node": ">=20" },
|
|
12
|
+
"scripts": { "test": "node --test test/*.test.mjs" },
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"keywords": ["lovable", "bolt", "v0", "replit", "supabase", "firebase", "vibe-coding", "security", "mcp", "ai-app-builder"],
|
|
15
|
+
"homepage": "https://greenlit.priberry.com",
|
|
16
|
+
"bugs": { "url": "https://github.com/priberry-data/greenlitlab/issues" },
|
|
17
|
+
"author": "Priberry",
|
|
18
|
+
"repository": { "type": "git", "url": "git+https://github.com/priberry-data/greenlitlab.git" },
|
|
19
|
+
"mcpName": "io.github.priberry-data/greenlitlab"
|
|
20
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.priberry-data/greenlitlab",
|
|
4
|
+
"title": "Greenlit",
|
|
5
|
+
"description": "Grade apps built with Lovable, Bolt, v0 or Replit A to F, with a fix prompt for every problem.",
|
|
6
|
+
"websiteUrl": "https://greenlit.priberry.com",
|
|
7
|
+
"repository": { "url": "https://github.com/priberry-data/greenlitlab", "source": "github" },
|
|
8
|
+
"version": "0.1.0",
|
|
9
|
+
"packages": [
|
|
10
|
+
{
|
|
11
|
+
"registryType": "npm",
|
|
12
|
+
"identifier": "greenlitlab",
|
|
13
|
+
"version": "0.1.0",
|
|
14
|
+
"transport": { "type": "stdio" },
|
|
15
|
+
"packageArguments": [{ "type": "positional", "value": "mcp" }]
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/grade.mjs
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
// greenlit <url>: checks a deployed app the way a curious stranger would, for the mistakes that
|
|
2
|
+
// AI app builders (Lovable, Bolt, v0, Replit, Emergent and the rest) ship most often:
|
|
3
|
+
// - secret keys inside the JavaScript every visitor downloads
|
|
4
|
+
// - a Supabase or Firebase database that anyone can read with the app's public key (with --mine only)
|
|
5
|
+
// - source maps that hand out the whole source code
|
|
6
|
+
// Every finding comes with a fix prompt to paste back into the app builder, and running the check again
|
|
7
|
+
// shows what got fixed. It reads only what the site serves to every visitor. The database checks ask for
|
|
8
|
+
// a row count (Supabase) or a single document name (Firebase), never for data, and run only when you say
|
|
9
|
+
// the app is yours.
|
|
10
|
+
// No Node-only imports here: the same code runs in the CLI and in the web check on Cloudflare.
|
|
11
|
+
import { SEVERITY } from "./severity.mjs";
|
|
12
|
+
|
|
13
|
+
// [pattern, id, what it is, what a stranger can do with it, where to revoke it]
|
|
14
|
+
const SECRETS = [
|
|
15
|
+
[/sk_live_[0-9A-Za-z]{20,}/, "stripe", "A live Stripe secret key", "Anyone can charge, refund and read your customers' payments.", "Stripe → Developers → API keys → Roll key", "STRIPE_SECRET_KEY"],
|
|
16
|
+
[/rk_live_[0-9A-Za-z]{20,}/, "stripe-restricted", "A live Stripe restricted key", "Anyone can do whatever this key allows on your Stripe account.", "Stripe → Developers → API keys → delete the restricted key", "STRIPE_RESTRICTED_KEY"],
|
|
17
|
+
[/sk-(proj|svcacct|admin)-[0-9A-Za-z_-]{20,}|sk-[0-9A-Za-z]{48}\b/, "openai", "An OpenAI API key", "Anyone can run up your OpenAI bill.", "platform.openai.com → API keys → revoke", "OPENAI_API_KEY"],
|
|
18
|
+
[/sk-ant-[0-9A-Za-z_-]{20,}/, "anthropic", "An Anthropic API key", "Anyone can run up your Anthropic bill.", "console.anthropic.com → API keys → disable", "ANTHROPIC_API_KEY"],
|
|
19
|
+
[/AKIA[0-9A-Z]{16}/, "aws", "An AWS access key", "Depending on its rights: your servers, storage and bill.", "AWS console → IAM → Users → Security credentials → deactivate the key", "AWS_SECRET_ACCESS_KEY"],
|
|
20
|
+
[/gh[pousr]_[0-9A-Za-z]{30,}|github_pat_[0-9A-Za-z_]{20,}/, "github", "A GitHub token", "Access to your code, and possibly the right to change it.", "GitHub → Settings → Developer settings → tokens → delete", "GITHUB_TOKEN"],
|
|
21
|
+
[/xox[bpas]-[0-9A-Za-z-]{10,}/, "slack", "A Slack token", "Anyone can read or post in your Slack.", "api.slack.com/apps → your app → reinstall to get a new token", "SLACK_TOKEN"],
|
|
22
|
+
[/re_[0-9A-Za-z]{8}_[0-9A-Za-z]{20,}/, "resend", "A Resend API key", "Anyone can send email as you.", "resend.com → API Keys → delete", "RESEND_API_KEY"],
|
|
23
|
+
[/SG\.[0-9A-Za-z_-]{20,}\.[0-9A-Za-z_-]{20,}/, "sendgrid", "A SendGrid API key", "Anyone can send email as you.", "SendGrid → Settings → API Keys → delete", "SENDGRID_API_KEY"],
|
|
24
|
+
[/AC[0-9a-f]{32}[^0-9a-f][\s\S]{0,80}?[0-9a-f]{32}/, "twilio", "Twilio credentials", "Anyone can send texts and make calls on your account.", "Twilio console → Account → API keys & tokens → rotate the auth token", "TWILIO_AUTH_TOKEN"],
|
|
25
|
+
[/gsk_[0-9A-Za-z]{40,}/, "groq", "A Groq API key", "Anyone can run up your Groq bill.", "console.groq.com → API Keys → delete", "GROQ_API_KEY"],
|
|
26
|
+
[/AIza[0-9A-Za-z_-]{35}(?=[\s\S]{0,400}(generativelanguage|gemini))/, "gemini", "A Google AI (Gemini) API key", "Anyone can run up your Gemini bill. (Firebase keys are public by design; this one sits next to Gemini calls.)", "aistudio.google.com → API keys → delete", "GEMINI_API_KEY"],
|
|
27
|
+
];
|
|
28
|
+
const JWT = /eyJ[0-9A-Za-z_-]{10,}\.eyJ[0-9A-Za-z_-]{10,}\.[0-9A-Za-z_-]{10,}/g;
|
|
29
|
+
const SUPABASE_URL = /https:\/\/([a-z0-9]{20})\.supabase\.co/;
|
|
30
|
+
const FB_PROJECT = /projectId["']?\s*:\s*["']([a-z0-9-]{4,40})["']/;
|
|
31
|
+
const FB_DB = /["'](https:\/\/[a-z0-9-]+(?:\.[a-z0-9-]+)*\.(?:firebaseio\.com|firebasedatabase\.app))\/?["']/;
|
|
32
|
+
const FB_KEY = /apiKey["']?\s*:\s*["'](AIza[0-9A-Za-z_-]{35})["']/;
|
|
33
|
+
// Firestore can't list its collections without admin rights, so try the names apps use for people and money.
|
|
34
|
+
const FIRESTORE_GUESSES = ["users", "profiles", "customers", "accounts", "orders", "payments", "messages", "chats", "leads", "contacts", "posts"];
|
|
35
|
+
const PERSONAL = /user|profile|customer|account|order|payment|message|chat|contact|lead|email|subscri|invoice/i;
|
|
36
|
+
|
|
37
|
+
// Which app builder made this, so the fix prompt can say where to paste it.
|
|
38
|
+
export function detectBuilder(host, html = "") {
|
|
39
|
+
const h = host.toLowerCase();
|
|
40
|
+
if (/\.lovable\.app$|\.lovableproject\.com$/.test(h) || /lovable-tagger|content=["']Lovable/i.test(html)) return "Lovable";
|
|
41
|
+
if (/\.bolt\.host$|\.bolt\.new$/.test(h)) return "Bolt";
|
|
42
|
+
if (/\.replit\.app$|\.repl\.co$|\.replit\.dev$/.test(h)) return "Replit";
|
|
43
|
+
if (/\.emergent\.host$|\.emergentagent\.com$|\.preview\.emergentagent\.com$/.test(h)) return "Emergent";
|
|
44
|
+
if (/\.base44\.app$/.test(h)) return "Base44";
|
|
45
|
+
if (/v0\.dev|v0\.app/.test(h) || /generated by v0/i.test(html)) return "v0";
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const decodeJwt = (t) => {
|
|
50
|
+
try {
|
|
51
|
+
const b = t.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
52
|
+
return JSON.parse(new TextDecoder().decode(Uint8Array.from(atob(b + "=".repeat((4 - (b.length % 4)) % 4)), (c) => c.charCodeAt(0))));
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
async function get(url, { timeout = 15000, headers = {}, method = "GET", max = 8 * 1024 * 1024, fetcher = fetch } = {}) {
|
|
59
|
+
const ctl = new AbortController();
|
|
60
|
+
const t = setTimeout(() => ctl.abort(), timeout);
|
|
61
|
+
try {
|
|
62
|
+
const r = await fetcher(url, { method, headers: { "user-agent": "greenlit (+https://greenlit.priberry.com)", ...headers }, signal: ctl.signal, redirect: "follow" });
|
|
63
|
+
const text = method === "HEAD" ? "" : (await r.text()).slice(0, max);
|
|
64
|
+
return { status: r.status, headers: r.headers, text, url: r.url };
|
|
65
|
+
} catch (e) {
|
|
66
|
+
return { status: 0, error: e.name === "AbortError" ? "timed out" : e.message, text: "" };
|
|
67
|
+
} finally {
|
|
68
|
+
clearTimeout(t);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// --- fix prompts ---------------------------------------------------------------------------------
|
|
73
|
+
// Written for someone who can't read the code: what to do by hand first (revoking a key is something
|
|
74
|
+
// no AI builder can do for you), then one prompt to paste into the builder's chat.
|
|
75
|
+
const P = {
|
|
76
|
+
secret: (label, revoke, env) => ({
|
|
77
|
+
first: `Revoke the leaked key, because it is already public: ${revoke}. Then make a new one, and give it only to your backend (in Supabase: Edge Functions → Secrets, named ${env}).`,
|
|
78
|
+
prompt: `My app has ${label.replace(/^A |^An /, "a ")} in its frontend code, so every visitor can download it. Remove that key from every frontend file. Move every call that uses it into a backend function (a Supabase Edge Function, or a server route if this app has a server) that reads the key from the secret ${env}, and have the frontend call that function instead. The function must check that the user is signed in before it does anything, and must never send the key back to the browser. When you're done, list every file you changed and confirm the key appears nowhere in the frontend.`,
|
|
79
|
+
}),
|
|
80
|
+
serviceRole: () => ({
|
|
81
|
+
first: "Rotate the key, because it is already public: Supabase → Project Settings → API → generate new keys (or reset the JWT secret), then update the apps and functions that use them.",
|
|
82
|
+
prompt: "My app has the Supabase service_role key in its frontend code. That key skips every security rule. Remove it from every frontend file; the browser must only ever use the anon (publishable) key. Anything that really needs admin access goes into a Supabase Edge Function that reads SUPABASE_SERVICE_ROLE_KEY from its environment and checks the signed-in user before acting. Then make sure Row Level Security is on for every table, with policies so users reach only their own rows. List what you changed.",
|
|
83
|
+
}),
|
|
84
|
+
rls: (table, personal) => ({
|
|
85
|
+
first: null,
|
|
86
|
+
prompt: personal
|
|
87
|
+
? `In my Supabase database, anyone on the internet can read the table "${table}" using the public anon key. Turn on Row Level Security for "${table}" and add policies so a signed-in user can read and change only their own rows: compare auth.uid() with the column that stores the owner's user id (if there is no such column, add user_id uuid references auth.users default auth.uid(), and fill it for existing rows). If some rows really must be public, add a separate read-only policy for just those rows and tell me which. Do not turn off any existing policy. Show me the SQL you ran.`
|
|
88
|
+
: `In my Supabase database, anyone on the internet can read the table "${table}" using the public anon key. First tell me in one sentence whether this app needs strangers to read "${table}" (a public product list or blog does; anything about specific users doesn't). If it should be public: turn on Row Level Security, add a policy that lets everyone read it, and allow insert, update and delete only for signed-in admins or the row's owner, so strangers can look but never change it. If it shouldn't be public: turn on Row Level Security and let a signed-in user reach only their own rows (auth.uid() = user_id). Do not turn off any existing policy. Show me the SQL you ran.`,
|
|
89
|
+
sql: personal
|
|
90
|
+
? `alter table public."${table}" enable row level security;\ncreate policy "own rows" on public."${table}" for all using (auth.uid() = user_id) with check (auth.uid() = user_id);`
|
|
91
|
+
: `alter table public."${table}" enable row level security;\ncreate policy "anyone can read" on public."${table}" for select using (true);`,
|
|
92
|
+
}),
|
|
93
|
+
rtdb: () => ({
|
|
94
|
+
first: null,
|
|
95
|
+
prompt: 'Anyone on the internet can read my Firebase Realtime Database. Rewrite the database rules so nothing is readable or writable without signing in, and each user can only reach their own data, for example under /users/$uid with ".read": "auth.uid === $uid" and ".write": "auth.uid === $uid". Keep public only what truly must be public, and tell me which paths those are. Show me the final rules.',
|
|
96
|
+
}),
|
|
97
|
+
firestore: (coll) => ({
|
|
98
|
+
first: null,
|
|
99
|
+
prompt: `Anyone on the internet can read the Firestore collection "${coll}". Rewrite my Firestore security rules so "${coll}" (and every other collection) is closed by default, and a signed-in user can only read and write documents they own, for example match /${coll}/{id} { allow read, write: if request.auth != null && request.auth.uid == resource.data.userId; }. Adjust the owner field to whatever this app uses. Show me the final rules.`,
|
|
100
|
+
}),
|
|
101
|
+
sourceMaps: () => ({
|
|
102
|
+
first: null,
|
|
103
|
+
prompt: "My production build publishes source maps, so anyone can read my app's original source code. Turn them off for production builds only (for Vite: build.sourcemap = false in vite.config), rebuild and redeploy. Don't change anything else.",
|
|
104
|
+
}),
|
|
105
|
+
csp: (origins) => ({
|
|
106
|
+
first: null,
|
|
107
|
+
prompt: `My app has no Content-Security-Policy. Add one as a <meta http-equiv="Content-Security-Policy"> tag in index.html (or as a response header if this host supports headers). Allow scripts, styles and fonts only from my own site and the services this app really uses${origins.length ? `, including ${origins.join(", ")}` : ""}, and allow connect-src for my backend and APIs. Then test every page and fix anything the policy blocks, without loosening it to allow everything.`,
|
|
108
|
+
}),
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// --- the check -----------------------------------------------------------------------------------
|
|
112
|
+
export async function siteScan(target, { mine = false, fetcher = fetch, maxScripts = 40 } = {}) {
|
|
113
|
+
const fetchOpts = (o = {}) => ({ ...o, fetcher });
|
|
114
|
+
const url = new URL(/^https?:\/\//.test(target) ? target : `https://${target}`);
|
|
115
|
+
const findings = [];
|
|
116
|
+
const add = (f) => findings.push(f);
|
|
117
|
+
|
|
118
|
+
const page = await get(url.href, fetchOpts());
|
|
119
|
+
if (!page.status || page.status >= 400) throw new Error(`could not load ${url.href} (${page.error || page.status})`);
|
|
120
|
+
const origin = new URL(page.url || url.href).origin;
|
|
121
|
+
const builder = detectBuilder(new URL(origin).host, page.text);
|
|
122
|
+
|
|
123
|
+
// Every script the page loads from its own site, plus the scripts those import.
|
|
124
|
+
const srcs = new Set();
|
|
125
|
+
const collect = (html, base) => {
|
|
126
|
+
for (const m of html.matchAll(/<script[^>]+src=["']([^"']+)["']/gi)) srcs.add(new URL(m[1], base).href);
|
|
127
|
+
for (const m of html.matchAll(/<link[^>]+href=["']([^"']+\.m?js)["']/gi)) srcs.add(new URL(m[1], base).href);
|
|
128
|
+
};
|
|
129
|
+
collect(page.text, origin);
|
|
130
|
+
const bundles = [{ where: "the page itself", text: page.text }];
|
|
131
|
+
const seen = new Set();
|
|
132
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
133
|
+
for (const src of [...srcs]) {
|
|
134
|
+
if (seen.has(src) || seen.size >= maxScripts || new URL(src).origin !== origin) continue;
|
|
135
|
+
seen.add(src);
|
|
136
|
+
const r = await get(src, fetchOpts());
|
|
137
|
+
if (r.status !== 200) continue;
|
|
138
|
+
bundles.push({ where: new URL(src).pathname, text: r.text, url: src });
|
|
139
|
+
for (const m of r.text.matchAll(/(?:import\(|from\s*)["'](\.{0,2}\/[^"']+\.m?js)["']/g)) srcs.add(new URL(m[1], src).href);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let supabase = null;
|
|
144
|
+
let firebase = null;
|
|
145
|
+
const keysSeen = new Set();
|
|
146
|
+
const thirdParty = new Set();
|
|
147
|
+
for (const b of bundles) {
|
|
148
|
+
for (const m of b.text.matchAll(/https:\/\/([a-z0-9-]+\.)+[a-z]{2,}/gi)) {
|
|
149
|
+
const o = new URL(m[0]).origin;
|
|
150
|
+
if (o !== origin && /supabase\.co|firebase|googleapis|stripe\.com|clerk|posthog|sentry|vercel/.test(o)) thirdParty.add(o.replace(/^https:\/\/[a-z0-9]{20}\.supabase\.co$/, "https://*.supabase.co"));
|
|
151
|
+
}
|
|
152
|
+
for (const [re, id, title, why, revoke, env] of SECRETS) {
|
|
153
|
+
const m = b.text.match(re);
|
|
154
|
+
if (m && !keysSeen.has(m[0])) {
|
|
155
|
+
keysSeen.add(m[0]);
|
|
156
|
+
add({ id: `secret:${id}`, severity: "critical", where: b.where, title: `${title} is in code every visitor downloads`, why: `${why} Found: ${m[0].slice(0, 8)}…`, fix: "Revoke this key now, make a new one, and call that service only from your backend (an edge function or server route), never from the browser.", ...P.secret(title, revoke, env) });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
for (const t of b.text.match(JWT) || []) {
|
|
160
|
+
const p = decodeJwt(t);
|
|
161
|
+
if (!p) continue;
|
|
162
|
+
if (p.role === "service_role" && !keysSeen.has(t)) {
|
|
163
|
+
keysSeen.add(t);
|
|
164
|
+
add({ id: "supabase:service_role", severity: "critical", where: b.where, title: "Your Supabase service_role key is in the browser code", why: "This key skips every security rule: anyone can read, change and delete all of your data and users.", fix: "Rotate it in Supabase (Settings → API) and use it only on a server. The browser should only ever have the anon key.", ...P.serviceRole() });
|
|
165
|
+
}
|
|
166
|
+
if (p.role === "anon" && p.iss === "supabase") supabase = { ...(supabase || {}), anon: t, ref: p.ref };
|
|
167
|
+
}
|
|
168
|
+
const pk = b.text.match(/sb_publishable_[0-9A-Za-z_-]{20,}/);
|
|
169
|
+
if (pk) supabase = { ...(supabase || {}), anon: supabase?.anon || pk[0] };
|
|
170
|
+
const su = b.text.match(SUPABASE_URL);
|
|
171
|
+
if (su) supabase = { ...(supabase || {}), url: su[0], ref: supabase?.ref || su[1] };
|
|
172
|
+
const fp = b.text.match(FB_PROJECT);
|
|
173
|
+
if (fp && /firebase/i.test(b.text)) {
|
|
174
|
+
firebase = { ...(firebase || {}), project: fp[1] };
|
|
175
|
+
const db = b.text.match(FB_DB);
|
|
176
|
+
if (db) firebase.db = db[1];
|
|
177
|
+
const k = b.text.match(FB_KEY);
|
|
178
|
+
if (k) firebase.key = k[1];
|
|
179
|
+
}
|
|
180
|
+
if (b.url && /sourceMappingURL=([^\s'"]+\.map)/.test(b.text)) {
|
|
181
|
+
const mapUrl = new URL(b.text.match(/sourceMappingURL=([^\s'"]+\.map)/)[1], b.url).href;
|
|
182
|
+
const r = await get(mapUrl, fetchOpts({ method: "HEAD" }));
|
|
183
|
+
if (r.status === 200 && !findings.some((f) => f.id === "sourcemaps"))
|
|
184
|
+
add({ id: "sourcemaps", severity: "medium", where: new URL(mapUrl).pathname, title: "Source maps are public", why: "Anyone can read your app's original source code, including comments and any logic you assumed was hidden.", fix: "Turn off source maps in production builds (for Vite: build.sourcemap = false).", ...P.sourceMaps() });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const database = supabase?.url && supabase.anon ? "Supabase" : firebase?.project ? "Firebase" : null;
|
|
189
|
+
if (database && !mine)
|
|
190
|
+
add({ id: "db:skipped", severity: "low", where: database, title: "Database checks skipped", why: `This app uses ${database}. Greenlit can check which of its data anyone on the internet can read, but only for an app you own.`, fix: `Run \`npx greenlitlab ${url.host} --mine\` if this is your app.`, first: null, prompt: null });
|
|
191
|
+
|
|
192
|
+
// Supabase: with the public anon key, which tables can anyone read?
|
|
193
|
+
let tables = null;
|
|
194
|
+
if (mine && supabase?.url && supabase.anon) {
|
|
195
|
+
// The newer sb_publishable_ keys aren't JWTs and go in the apikey header only.
|
|
196
|
+
const h = { apikey: supabase.anon, ...(supabase.anon.startsWith("eyJ") && { authorization: `Bearer ${supabase.anon}` }) };
|
|
197
|
+
const api = await get(`${supabase.url}/rest/v1/`, fetchOpts({ headers: h }));
|
|
198
|
+
let names = [];
|
|
199
|
+
try {
|
|
200
|
+
names = Object.keys(JSON.parse(api.text).paths || {}).map((p) => p.slice(1)).filter((p) => p && !p.startsWith("rpc/"));
|
|
201
|
+
} catch {}
|
|
202
|
+
tables = [];
|
|
203
|
+
for (const t of names.slice(0, 60)) {
|
|
204
|
+
// A HEAD request with count=exact returns how many rows are visible, and no rows.
|
|
205
|
+
const r = await get(`${supabase.url}/rest/v1/${encodeURIComponent(t)}?select=*`, fetchOpts({ method: "HEAD", headers: { ...h, prefer: "count=exact", range: "0-0" } }));
|
|
206
|
+
const n = Number((r.headers?.get("content-range") || "").split("/")[1]);
|
|
207
|
+
if (r.status < 300 && n > 0) tables.push({ table: t, rows: n });
|
|
208
|
+
}
|
|
209
|
+
for (const { table, rows } of tables) {
|
|
210
|
+
const personal = PERSONAL.test(table);
|
|
211
|
+
const why = personal
|
|
212
|
+
? "The anon key is public (it ships in your app), so a table without Row Level Security is readable by everyone. This is how most vibe-coded apps have leaked data."
|
|
213
|
+
: "The anon key is public (it ships in your app). If this table is meant to be public, like a product list, reading it is fine, but make sure strangers can't change it. If it isn't, it's leaking.";
|
|
214
|
+
add({ id: `supabase:table:${table}`, severity: personal ? "critical" : "medium", where: `Supabase table "${table}"`, title: `Anyone on the internet can read ${rows.toLocaleString("en-US")} row${rows > 1 ? "s" : ""} of "${table}"`, why, fix: `In Supabase, open Table Editor → ${table} → turn on RLS, then add a policy so people read only their own rows (for example: auth.uid() = user_id).`, ...P.rls(table, personal) });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Firebase: is the Realtime Database or a common Firestore collection open to anyone?
|
|
219
|
+
let firebaseOpen = null;
|
|
220
|
+
if (mine && firebase?.project) {
|
|
221
|
+
firebaseOpen = [];
|
|
222
|
+
if (firebase.db) {
|
|
223
|
+
// shallow=true returns only the top-level key names, each mapped to true; we count them and drop them.
|
|
224
|
+
const r = await get(`${firebase.db}/.json?shallow=true`, fetchOpts());
|
|
225
|
+
let keys = 0;
|
|
226
|
+
try {
|
|
227
|
+
const v = JSON.parse(r.text);
|
|
228
|
+
keys = v && typeof v === "object" ? Object.keys(v).length : v != null ? 1 : 0;
|
|
229
|
+
} catch {}
|
|
230
|
+
if (r.status === 200 && keys > 0) {
|
|
231
|
+
firebaseOpen.push({ where: "Realtime Database", keys });
|
|
232
|
+
add({ id: "firebase:rtdb", severity: "critical", where: "Firebase Realtime Database", title: "Anyone on the internet can read your Firebase Realtime Database", why: `Its rules let visitors who aren't signed in read it (${keys} top-level ${keys > 1 ? "branches" : "branch"} visible). Everything under them is open.`, fix: "In Firebase → Realtime Database → Rules, require sign-in and limit each user to their own data.", ...P.rtdb() });
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
for (const coll of FIRESTORE_GUESSES) {
|
|
236
|
+
// pageSize=1 and a mask on a field that doesn't exist: at most one document name comes back, no fields.
|
|
237
|
+
const q = `pageSize=1&mask.fieldPaths=__greenlit_none${firebase.key ? `&key=${firebase.key}` : ""}`;
|
|
238
|
+
const r = await get(`https://firestore.googleapis.com/v1/projects/${firebase.project}/databases/(default)/documents/${coll}?${q}`, fetchOpts());
|
|
239
|
+
let n = 0;
|
|
240
|
+
try {
|
|
241
|
+
n = (JSON.parse(r.text).documents || []).length;
|
|
242
|
+
} catch {}
|
|
243
|
+
if (r.status === 200 && n > 0) {
|
|
244
|
+
firebaseOpen.push({ where: `Firestore "${coll}"` });
|
|
245
|
+
add({ id: `firebase:firestore:${coll}`, severity: PERSONAL.test(coll) ? "critical" : "high", where: `Firestore collection "${coll}"`, title: `Anyone on the internet can read the Firestore collection "${coll}"`, why: "Your Firestore rules let visitors who aren't signed in read it. Greenlit asked for one document name and no fields; a stranger would take everything.", fix: `In Firebase → Firestore → Rules, close "${coll}" to everyone except its owner.`, ...P.firestore(coll) });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (!page.headers?.get("content-security-policy") && !/http-equiv=["']Content-Security-Policy/i.test(page.text))
|
|
251
|
+
add({ id: "csp", severity: "low", where: "response headers", title: "No Content-Security-Policy", why: "If an attacker gets a script into the page (through a comment, a profile field or a dependency), nothing stops it from sending your users' data out.", fix: "Add a Content-Security-Policy header in your host's settings.", ...P.csp([...thirdParty].slice(0, 6)) });
|
|
252
|
+
|
|
253
|
+
const penalty = findings.reduce((a, f) => a + SEVERITY[f.severity], 0);
|
|
254
|
+
const score = Math.max(0, 100 - penalty);
|
|
255
|
+
const grade = score >= 90 ? "A" : score >= 75 ? "B" : score >= 60 ? "C" : score >= 40 ? "D" : "F";
|
|
256
|
+
const order = ["critical", "high", "medium", "low"];
|
|
257
|
+
findings.sort((a, b) => order.indexOf(a.severity) - order.indexOf(b.severity));
|
|
258
|
+
return {
|
|
259
|
+
url: origin,
|
|
260
|
+
builder,
|
|
261
|
+
score,
|
|
262
|
+
grade,
|
|
263
|
+
verdict: VERDICT[grade],
|
|
264
|
+
mine,
|
|
265
|
+
scripts: bundles.length - 1,
|
|
266
|
+
supabase: supabase ? { project: supabase.ref, checked: mine, readable: tables } : null,
|
|
267
|
+
firebase: firebase ? { project: firebase.project, checked: mine, readable: firebaseOpen } : null,
|
|
268
|
+
findings,
|
|
269
|
+
pasteInto: builder || "your AI app builder or coding agent",
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export const VERDICT = {
|
|
274
|
+
A: "Nothing serious a stranger can use against you.",
|
|
275
|
+
B: "No open doors, a few loose ends.",
|
|
276
|
+
C: "Fix these before you share the link widely.",
|
|
277
|
+
D: "A stranger can do real damage. Fix the red items today.",
|
|
278
|
+
F: "Your users' data or your accounts are exposed right now. Fix the red items before anything else.",
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// --- re-check ------------------------------------------------------------------------------------
|
|
282
|
+
// What changed between two runs: fixed, still open, new.
|
|
283
|
+
export function compare(prev, result) {
|
|
284
|
+
if (!prev) return null;
|
|
285
|
+
const now = new Map(result.findings.map((f) => [f.id, f]));
|
|
286
|
+
const before = new Map(prev.findings.map((f) => [f.id, f]));
|
|
287
|
+
return {
|
|
288
|
+
since: prev.at,
|
|
289
|
+
before: { score: prev.score, grade: prev.grade },
|
|
290
|
+
after: { score: result.score, grade: result.grade },
|
|
291
|
+
fixed: prev.findings.filter((f) => !now.has(f.id)).map((f) => f.title),
|
|
292
|
+
open: result.findings.filter((f) => before.has(f.id)).map((f) => f.title),
|
|
293
|
+
new: result.findings.filter((f) => !before.has(f.id)).map((f) => f.title),
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// --- the report a person reads ---------------------------------------------------------------------
|
|
298
|
+
const wrap = (s, w = 92, pad = " ") => {
|
|
299
|
+
const out = [];
|
|
300
|
+
for (const para of String(s).split("\n")) {
|
|
301
|
+
let line = "";
|
|
302
|
+
for (const word of para.split(" ")) {
|
|
303
|
+
if ((line + " " + word).trim().length > w) (out.push(pad + line.trim()), (line = word));
|
|
304
|
+
else line += " " + word;
|
|
305
|
+
}
|
|
306
|
+
out.push(pad + line.trim());
|
|
307
|
+
}
|
|
308
|
+
return out.join("\n");
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
export function renderSite(r, change, { color = true, mine = r.mine } = {}) {
|
|
312
|
+
const k = (code) => (s) => (color ? `\x1b[${code}m${s}\x1b[0m` : s);
|
|
313
|
+
const red = k("31"), green = k("32"), yellow = k("33"), dim = k("2"), bold = k("1"), cyan = k("36");
|
|
314
|
+
const col = { critical: red, high: red, medium: yellow, low: dim };
|
|
315
|
+
const gcol = r.score >= 75 ? green : r.score >= 55 ? yellow : red;
|
|
316
|
+
const L = [];
|
|
317
|
+
L.push("", `${bold("Greenlit check")} · ${r.url}${r.builder ? ` · built with ${r.builder}` : ""} · ${r.scripts} scripts read${r.supabase ? " · Supabase" : ""}${r.firebase ? " · Firebase" : ""}`, "");
|
|
318
|
+
L.push(` Grade ${gcol(bold(r.grade))} ${gcol(`${r.score}/100`)} ${r.verdict}`);
|
|
319
|
+
if (change) {
|
|
320
|
+
const arrow = change.after.score > change.before.score ? green : change.after.score < change.before.score ? red : dim;
|
|
321
|
+
L.push(` ${arrow(`Was ${change.before.grade} (${change.before.score}) on ${change.since.slice(0, 10)}, now ${change.after.grade} (${change.after.score}).`)}`);
|
|
322
|
+
for (const t of change.fixed) L.push(` ${green("✓ fixed")} ${t}`);
|
|
323
|
+
for (const t of change.new) L.push(` ${red("+ new")} ${t}`);
|
|
324
|
+
if (!change.fixed.length && !change.new.length) L.push(dim(" Nothing changed since the last check."));
|
|
325
|
+
}
|
|
326
|
+
L.push("");
|
|
327
|
+
if (!r.findings.length) L.push(green(" Nothing found."), "");
|
|
328
|
+
let n = 0;
|
|
329
|
+
for (const f of r.findings) {
|
|
330
|
+
const num = f.prompt ? `${++n}.` : " ";
|
|
331
|
+
L.push(`${num.padStart(3)} ${col[f.severity](f.severity.toUpperCase().padEnd(8))} ${bold(f.title)} ${dim(`(${f.where})`)}`);
|
|
332
|
+
L.push(wrap(f.why, 88, " "));
|
|
333
|
+
if (f.first) L.push(wrap(`${yellow("Do this yourself first:")} ${f.first}`, 88, " "));
|
|
334
|
+
if (f.prompt) {
|
|
335
|
+
L.push(` ${cyan(`Then paste this into ${r.pasteInto}:`)}`);
|
|
336
|
+
L.push(wrap(f.prompt, 84, ` ${dim("│")} `));
|
|
337
|
+
} else L.push(wrap(`${green("Next:")} ${f.fix}`, 88, " "));
|
|
338
|
+
L.push("");
|
|
339
|
+
}
|
|
340
|
+
L.push(dim(`Read only what the site serves to every visitor${mine ? "; database checked with counts and names only, never data" : ""}.`));
|
|
341
|
+
if (n) {
|
|
342
|
+
L.push(dim(`Fix the red items first, one prompt at a time. Copy one prompt: npx greenlitlab ${new URL(r.url).host}${mine ? " --mine" : ""} --prompt 1 | pbcopy`));
|
|
343
|
+
L.push(dim("After the fixes are live, run this same command again: it shows what got fixed."));
|
|
344
|
+
}
|
|
345
|
+
return L.join("\n");
|
|
346
|
+
}
|
package/src/history.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
// The last result for each site is kept on this machine (ids, titles and score only: no keys, no data),
|
|
6
|
+
// so running the check again shows what the fixes changed.
|
|
7
|
+
const HISTORY = () => path.join(process.env.GREENLIT_HOME ?? path.join(os.homedir(), ".greenlit"), "sites");
|
|
8
|
+
const historyFile = (origin, mine, dir) => path.join(dir, `${new URL(origin).host.replace(/[^\w.-]/g, "_")}${mine ? ".mine" : ""}.json`);
|
|
9
|
+
|
|
10
|
+
export function loadLast(origin, mine, dir = HISTORY()) {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(fs.readFileSync(historyFile(origin, mine, dir), "utf8"));
|
|
13
|
+
} catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function saveRun(result, dir = HISTORY()) {
|
|
19
|
+
const slim = { at: new Date().toISOString(), score: result.score, grade: result.grade, findings: result.findings.map(({ id, severity, title }) => ({ id, severity, title })) };
|
|
20
|
+
try {
|
|
21
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
22
|
+
fs.writeFileSync(historyFile(result.url, result.mine, dir), JSON.stringify(slim, null, 2) + "\n");
|
|
23
|
+
} catch {}
|
|
24
|
+
return slim;
|
|
25
|
+
}
|
|
26
|
+
|
package/src/mcp.mjs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Greenlit as an MCP server (stdio, newline-delimited JSON-RPC), so an agent in Claude, Cursor or VS Code
|
|
2
|
+
// can grade the app it just deployed and apply the fix prompts itself.
|
|
3
|
+
import readline from "node:readline";
|
|
4
|
+
import { siteScan, compare } from "./grade.mjs";
|
|
5
|
+
|
|
6
|
+
const TOOLS = [
|
|
7
|
+
{
|
|
8
|
+
name: "greenlit_check",
|
|
9
|
+
description:
|
|
10
|
+
"Grade a deployed web app (built with Lovable, Bolt, v0, Replit, Emergent or by hand) A to F for what a stranger can use against it: secret keys shipped in its JavaScript, a Supabase service_role key in the browser, source maps, missing security headers. Every finding has a plain-English reason and a fix prompt. Reads only what the site serves to every visitor. Call it again after a fix: `change` shows what got fixed. For database checks on the user's own app, have them run `npx greenlitlab <url> --mine`.",
|
|
11
|
+
inputSchema: { type: "object", properties: { url: { type: "string", description: "The app's address, for example myapp.lovable.app" } }, required: ["url"], additionalProperties: false },
|
|
12
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
13
|
+
},
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const last = new Map();
|
|
17
|
+
|
|
18
|
+
async function call(name, args = {}) {
|
|
19
|
+
if (name !== "greenlit_check") throw new Error(`unknown tool ${name}`);
|
|
20
|
+
const result = await siteScan(args.url, { mine: false });
|
|
21
|
+
// Remembered for this session only, so a second call shows what the fixes changed.
|
|
22
|
+
const change = compare(last.get(result.url), result);
|
|
23
|
+
last.set(result.url, { at: new Date().toISOString(), score: result.score, grade: result.grade, findings: result.findings.map(({ id, severity, title }) => ({ id, severity, title })) });
|
|
24
|
+
return { ...result, change };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function serve({ version, input = process.stdin, output = process.stdout } = {}) {
|
|
28
|
+
const send = (msg) => output.write(JSON.stringify({ jsonrpc: "2.0", ...msg }) + "\n");
|
|
29
|
+
const rl = readline.createInterface({ input, crlfDelay: Infinity });
|
|
30
|
+
const pending = new Set();
|
|
31
|
+
rl.on("line", (line) => {
|
|
32
|
+
const job = handle(line).finally(() => pending.delete(job));
|
|
33
|
+
pending.add(job);
|
|
34
|
+
});
|
|
35
|
+
async function handle(line) {
|
|
36
|
+
let m;
|
|
37
|
+
try {
|
|
38
|
+
m = JSON.parse(line);
|
|
39
|
+
} catch {
|
|
40
|
+
return send({ id: null, error: { code: -32700, message: "parse error" } });
|
|
41
|
+
}
|
|
42
|
+
if (m.id === undefined) return;
|
|
43
|
+
if (m.method === "initialize")
|
|
44
|
+
return send({ id: m.id, result: { protocolVersion: m.params?.protocolVersion || "2025-06-18", capabilities: { tools: {} }, serverInfo: { name: "greenlit", version } } });
|
|
45
|
+
if (m.method === "ping") return send({ id: m.id, result: {} });
|
|
46
|
+
if (m.method === "tools/list") return send({ id: m.id, result: { tools: TOOLS } });
|
|
47
|
+
if (m.method === "tools/call") {
|
|
48
|
+
try {
|
|
49
|
+
const r = await call(m.params?.name, m.params?.arguments);
|
|
50
|
+
return send({ id: m.id, result: { content: [{ type: "text", text: JSON.stringify(r, null, 2) }], structuredContent: r } });
|
|
51
|
+
} catch (e) {
|
|
52
|
+
return send({ id: m.id, result: { content: [{ type: "text", text: `greenlit: ${e.message}` }], isError: true } });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
send({ id: m.id, error: { code: -32601, message: `method not found: ${m.method}` } });
|
|
56
|
+
}
|
|
57
|
+
// Let a check still running answer before the server exits.
|
|
58
|
+
return new Promise((resolve) => rl.on("close", () => Promise.allSettled([...pending]).then(resolve)));
|
|
59
|
+
}
|
package/src/severity.mjs
ADDED