@examplary/cli 1.11.0 → 1.11.1
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/dist/commands/preview.js +14 -3
- package/dist/lib/safe-path.d.ts +5 -0
- package/dist/lib/safe-path.js +13 -0
- package/dist/preview-ui/assets/index-drvY5o6H.js +3637 -0
- package/dist/preview-ui/assets/{index-BOd-WLRR.js.map → index-drvY5o6H.js.map} +1 -1
- package/dist/preview-ui/index.html +1 -1
- package/package.json +5 -5
- package/dist/preview-ui/assets/index-BOd-WLRR.js +0 -3636
package/dist/commands/preview.js
CHANGED
|
@@ -12,6 +12,7 @@ import { WebSocketServer } from "ws";
|
|
|
12
12
|
import { setApiHost, setApiKey } from "../lib/api.js";
|
|
13
13
|
import { buildComponent } from "../lib/bundle.js";
|
|
14
14
|
import { readJsonOrYamlFile, readMetaFile } from "../lib/read-meta.js";
|
|
15
|
+
import { resolveInside } from "../lib/safe-path.js";
|
|
15
16
|
import { buildStyles } from "../lib/styles.js";
|
|
16
17
|
export const previewCommand = async (argv) => {
|
|
17
18
|
setApiHost(argv.host);
|
|
@@ -33,7 +34,7 @@ export const previewCommand = async (argv) => {
|
|
|
33
34
|
const sourcemap = c.req.query("sourcemap") === "1";
|
|
34
35
|
const componentName = c.req.query("componentName");
|
|
35
36
|
try {
|
|
36
|
-
const componentOutput = await buildComponent(path);
|
|
37
|
+
const componentOutput = await buildComponent(resolveInside(dir, path));
|
|
37
38
|
if (sourcemap) {
|
|
38
39
|
return c.body(componentOutput.sourcemap, 200, {
|
|
39
40
|
"Content-Type": "application/json",
|
|
@@ -60,7 +61,13 @@ export const previewCommand = async (argv) => {
|
|
|
60
61
|
});
|
|
61
62
|
app.get("/api/icon", async (c) => {
|
|
62
63
|
const path = c.req.query("path") || "";
|
|
63
|
-
|
|
64
|
+
let icon;
|
|
65
|
+
try {
|
|
66
|
+
icon = await readFile(resolveInside(dir, path), "utf-8");
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
return c.text(`Error reading icon from ${path}: ${error.message}`, 400);
|
|
70
|
+
}
|
|
64
71
|
return c.body(icon, 200, {
|
|
65
72
|
"Content-Type": "image/svg+xml",
|
|
66
73
|
});
|
|
@@ -171,7 +178,11 @@ export const previewCommand = async (argv) => {
|
|
|
171
178
|
watcher.close();
|
|
172
179
|
process.exit(0);
|
|
173
180
|
});
|
|
174
|
-
serve({
|
|
181
|
+
serve({
|
|
182
|
+
fetch: app.fetch,
|
|
183
|
+
hostname: "localhost",
|
|
184
|
+
port: 5777,
|
|
185
|
+
}, (address) => {
|
|
175
186
|
const port = address.port;
|
|
176
187
|
wsPort = port + 1234;
|
|
177
188
|
const wsServer = createHttpServer();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { resolve, sep } from "path";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves `path` against `dir` and throws if the result escapes `dir`,
|
|
4
|
+
* preventing path traversal via `../` segments or absolute paths.
|
|
5
|
+
*/
|
|
6
|
+
export const resolveInside = (dir, path) => {
|
|
7
|
+
const base = resolve(dir);
|
|
8
|
+
const resolved = resolve(base, path);
|
|
9
|
+
if (resolved !== base && !resolved.startsWith(base + sep)) {
|
|
10
|
+
throw new Error(`Path "${path}" is outside of the question type directory`);
|
|
11
|
+
}
|
|
12
|
+
return resolved;
|
|
13
|
+
};
|