-
Notifications
You must be signed in to change notification settings - Fork 0
Generator v3.0.0 #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1ddde82
d8a61d5
d7f6d02
3172f54
9a2f06b
8422792
3d43669
6e162f9
88d6325
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,4 @@ mount | |
| **temp | ||
| *key* | ||
| *keys* | ||
| test | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| npm run dev |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,46 @@ app.use( | |
| ); | ||
| app.use(express.json()); | ||
|
|
||
| // NON_SUBNET mode: when NON_SUBNET=true, block every subnet-management route | ||
| // (including the wizard landing page "/") so only the XDPoS private-network | ||
| // generator (/gen_xdpos, /submit_xdpos) remains reachable. | ||
| const NON_SUBNET = process.env.NON_SUBNET === "true"; | ||
| const SUBNET_ROUTES = [ | ||
| "/", | ||
| "/debug", | ||
| "/state", | ||
| "/deploy_csc_lite", | ||
| "/deploy_csc_full", | ||
| "/deploy_csc_reversefull", | ||
| "/deploy_zero", | ||
| "/deploy_subswap", | ||
| "/start_subnet", | ||
| "/stop_subnet", | ||
| "/start_subnet_slow", | ||
| "/start_services", | ||
| "/stop_services", | ||
| "/start_subswap_frontend", | ||
| "/stop_subswap_frontend", | ||
| "/start_explorer", | ||
| "/stop_explorer", | ||
| "/remove_subnet", | ||
| "/gen", | ||
| "/submit", | ||
| "/submit_preconfig", | ||
| "/faucet", | ||
| "/faucet_subnet", | ||
| ]; | ||
|
|
||
| app.use((req, res, next) => { | ||
| if (NON_SUBNET && SUBNET_ROUTES.includes(req.path)) { | ||
| console.log(`NON_SUBNET: blocked ${req.path}`); | ||
| return res | ||
| .status(403) | ||
| .json({ error: "Subnet routes are disabled (NON_SUBNET mode)" }); | ||
| } | ||
| next(); | ||
|
Comment on lines
+55
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf 'Files matching express.js:\n'
fd -a 'express\.js$' . || true
printf '\nRelevant file excerpts:\n'
for f in $(fd 'express\.js$' .); do
echo "--- $f"
wc -l "$f"
sed -n '1,140p' "$f" | cat -n
done
printf '\nSubnet route declarations/usages:\n'
rg -n "SUBNET_ROUTES|/submit|submit|strictRouting|strict routing" container-manager/src || true
printf '\nPackage Express version if available:\n'
fd 'package\.json$' -d 5 . | xargs -r -n1 sh -c 'echo "--- $0"; jq ".dependencies.express, .devDependencies.express" "$0"'Repository: XinFinOrg/Subnet-Deployment Length of output: 50383 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf 'Package.json/lock Express entries (if present):\n'
for f in $(fd 'package(-lock)?\.json$' -d 4 .); do
echo "--- $f"
jq -r '(.dependencies.express?, .devDependencies.express? // keys[]?|select(startswith("express@"))? // "none", (.["express@*"] // {})|keys[]?|select(startswith("express@"))? // "none")|select(type=="string")' "$f" 2>/dev/null || true
done
printf '\nRest of express.js route handlers and strict settings:\n'
sed -n '140,225p' container-manager/src/express.js | cat -n
grep -En "strictRouting|app\(strict|strict\(\)" container-manager/src || true
printf '\nProgrammatic simulation of current middleware vs Express-style non-strict GET routes for /submit and /submit/.submit variants:\n'
python3 - <<'PY'
BLOCKED = ["/submit", "/submit_preconfig", "/debug", "/"]
def current_checks(path):
return path in BLOCKED
def express_like_matches(handler_path, req_path):
if handler_path.endswith("/"):
return req_path == handler_path or (handler_path[:-1] == req_path)
return req_path == handler_path or req_path == handler_path + "/"
handler = "/submit"
for req_path in ["/submit", "/submit/", "/submit.submit", "/submit/submit", "/debug/"]:
print(f"{req_path!r}: blocked={current_checks(req_path)} matching={express_like_matches(handler, req_path)}")
PYRepository: XinFinOrg/Subnet-Deployment Length of output: 3664 🌐 Web query:
💡 Result: In Express.js, both version 4.x and 5.x provide a strict routing option that controls how the router handles trailing slashes in request paths [1][2]. By default, the strict routing option is disabled (false) [1][2]. When it is disabled, Express treats paths with and without a trailing slash (e.g., /foo and /foo/) as identical, meaning they will match the same route [1][2]. When the strict routing option is enabled (true), the router treats /foo and /foo/ as distinct, different routes [1][3]. To enable this behavior, you can pass the strict: true option when creating a router instance [1][2]: const router = express.Router({ strict: true }); This setting applies to the specific router instance. If you are using the main application object as a router, note that Express applications do not typically expose a direct configuration option for strict routing at the app level in the same way, though you can use a mounted router to enforce this behavior for specific sub-paths [1][2]. Citations:
Normalize paths before checking blocked routes. Exact matching lets trailing-slash variants such as 🧰 Tools🪛 ast-grep (0.44.1)[warning] 56-56: Logging request-derived input unsanitized allows log forging (CRLF injection); strip newlines / encode the value before logging. (log-injection-javascript) 🤖 Prompt for AI Agents |
||
| }); | ||
|
|
||
| app.get("/", (req, res) => { | ||
| res.sendFile(path.join(__dirname, "views", "index.html")); | ||
| }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "$schema": "https://raw.githubusercontent.com/NethermindEth/core-scripts/refs/heads/main/schemas/config.json", | ||
| "Init": { | ||
| "ChainSpecPath": "/work/chainspec.json", | ||
| "BaseDbPath": "nethermind_db/xdc-nmc", | ||
| "LogFileName": "xdc.log", | ||
| "StateDbKeyScheme": "Hash", | ||
| "AutoDump": "All" | ||
| }, | ||
| "TxPool": { | ||
| "BlobsSupport": "Disabled" | ||
| }, | ||
| "Sync": { | ||
| "FastSync": true, | ||
| "NeedToWaitForHeader": true, | ||
| "VerifyTrieOnStateSyncFinished": true | ||
| }, | ||
| "Mining": { | ||
| "Enabled": true | ||
| }, | ||
| "JsonRpc": { | ||
| "Enabled": true | ||
| }, | ||
| "Blocks": { | ||
| "TargetBlockGasLimit": 50000000 | ||
| }, | ||
| "Merge": { | ||
| "Enabled": false | ||
| }, | ||
| "TraceStore": { | ||
| "Enabled": false | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,6 +180,33 @@ function generateXdpos(params) { | |
| command = `cd ${mountPath}; docker run -v ${config.hostPath}:/app/generated/ --entrypoint 'bash' ${versionGenesisFullname} /work/puppeth.sh`; | ||
| console.log(command); | ||
| const [result2, out2] = callExec(command); | ||
| if (!result2) { | ||
| return [result2, out2]; | ||
| } | ||
|
|
||
| //step 3: convert genesis.json -> chainspec.json (needed by Nethermind nodes) | ||
| const nethermindCount = | ||
| "customversion-checkbox" in params && | ||
| params["customversion-checkbox"] != "" | ||
| ? parseInt(params["customversion-xdpos-nethermind-count"]) || 0 | ||
| : 0; | ||
|
Comment on lines
+188
to
+192
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== file sizes =="
wc -l container-manager/src/libs/exec.js container-manager/src/views/xdpos_generator/index.pug
echo "== relevant exec.js sections =="
sed -n '160,210p' container-manager/src/libs/exec.js
sed -n '380,420p' container-manager/src/libs/exec.js
echo "== relevant pug section =="
sed -n '80,100p' container-manager/src/views/xdpos_generator/index.pug
echo "== JS parse/runtime behavior probe =="
node - <<'JS'
const input = { "customversion-checkbox": "on", "customversion-xdpos-nethermind-count": "1e3" };
const nethermindCount =
"customversion-checkbox" in input &&
input["customversion-checkbox"] != ""
? parseInt(input["customversion-xdpos-nethermind-count"]) || 0
: 0;
const emissionCondition = "customversion-checkbox" in input && input["customversion-checkbox"] != "" && "customversion-xdpos-nethermind-count" in input && input["customversion-xdpos-nethermind-count"] != "";
console.log({
parseIntValue: nethermindCount,
emissionCondition,
emittedLine: emissionCondition ? `NUM_NETHERMIND=${input["customversion-xdpos-nethermind-count"]}` : "",
isNaNNegative: isNaN(parseInt(input["customversion-xdpos-nethermind-count"])),
});
for (const value of ["-5", "", "abc", "3.7", "9007199254740991", "9007199254740992"]) {
console.log(value, parseInt(value, 10));
}
JS
echo "== search for Nethermind count handling =="
rg -n "customversion-xdpos-nethermind-count|NUM_NETHERMIND|nethermind" container-manager/srcRepository: XinFinOrg/Subnet-Deployment Length of output: 8224 Validate and canonicalize the Nethermind count before storing/updating it.
🧰 Tools🪛 ast-grep (0.44.1)[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec. (detect-child-process) 📍 Affects 2 files
🤖 Prompt for AI Agents |
||
| if (nethermindCount > 0) { | ||
| try { | ||
| const { translate } = require("./genesis-to-chainspec"); | ||
| const genesis = JSON.parse( | ||
| fs.readFileSync(path.join(mountPath, "genesis.json"), "utf-8") | ||
| ); | ||
| const chainspec = translate(genesis, {}); | ||
| fs.writeFileSync( | ||
| path.join(mountPath, "chainspec.json"), | ||
| JSON.stringify(chainspec, null, 2) + "\n" | ||
| ); | ||
| console.log("chainspec.json generated"); | ||
| } catch (e) { | ||
| console.error("chainspec generation failed:", e.message); | ||
| return [false, `chainspec generation failed: ${e.message}`]; | ||
| } | ||
| } | ||
| return [result2, out2]; | ||
| } | ||
|
|
||
|
|
@@ -374,6 +401,14 @@ function genGenXdposEnv(input){ | |
| if ("customversion-checkbox" in input && input["customversion-checkbox"] != "" && "customversion-xdpos-node-fullname" in input && input["customversion-xdpos-node-fullname"] != "") { | ||
| content_version += `\nVERSION_NODE_IMAGE=${input["customversion-xdpos-node-fullname"]}`; | ||
| } | ||
| if ("customversion-checkbox" in input && input["customversion-checkbox"] != "" && "customversion-xdpos-nethermind-count" in input && input["customversion-xdpos-nethermind-count"] != "") { | ||
| content_version += `\nNUM_NETHERMIND=${input["customversion-xdpos-nethermind-count"]}`; | ||
| } | ||
| if ("customversion-checkbox" in input && input["customversion-checkbox"] != "" && "customversion-xdpos-nethermind-version" in input && input["customversion-xdpos-nethermind-version"] != "") { | ||
| content_version += `\nVERSION_NETHERMIND_IMAGE=${input["customversion-xdpos-nethermind-version"]}`; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| let content_rewards = ""; | ||
| if ("customrewards-checkbox" in input && input["customrewards-checkbox"] != "") { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Do not ignore every
testpath.A slashless
testpattern recursively ignores any file or directory with that name, which can silently exclude test source. Remove it or scope it to the intended generated artifact.🤖 Prompt for AI Agents