Skip to content

Better nsjail - #53

Draft
EnderHubris wants to merge 3 commits into
developfrom
better-nsjail
Draft

Better nsjail#53
EnderHubris wants to merge 3 commits into
developfrom
better-nsjail

Conversation

@EnderHubris

Copy link
Copy Markdown
Member

Items regarding nsjail are better-worded in hopes to reduce confusion by admins. Jails can be widely configured through special json config files, there is a HANDLER.md that contains documentation for these nsjail config files. These configurations allow admins making challenges to set the main binary nsjail will execute along with defining a list of files the jail must contain to properly function.

EnderHubris and others added 3 commits July 28, 2026 17:31
Migrating in-transit flag handling into this branch.
Locally composed image the improved handler works!
@EnderHubris
EnderHubris requested a review from Monster0506 July 30, 2026 03:54
@EnderHubris EnderHubris added the enhancement New feature or request label Jul 30, 2026

@Monster0506 Monster0506 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than these few things, LGTM!

Comment thread handler/handler.js

if (requestedPath.startsWith(BINS_FOLDER)) {
// check executable binary files
if (await CheckFile(BINS_FOLDER, jail_bin)) continue;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always be true as CheckFile() always resolves to an object ({success, rc, message}), never false.So this continue fires, meaning ParseJailConfig never rejects a config that references a missing challenge binary or entrypoint. Destructure success here, like line 124 does: const { success, rc, message } = await CheckFile(NSJAIL_CONFS_FOLDER, nsjail_conf, false);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch! That's a simple fix, I probably repeated this in other places so I'll double check when I get to this.

Comment thread handler/server.js

if (!MIN_PORT || !MAX_PORT || !BINS_FOLDER) {
console.error("[-] Missing values for MIN_PORT and MAX_PORT!")
if (MIN_PORT === MAX_PORT) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If only one of the two env vars is actually missing (e.g. MIN_PORT=5000, MAX_PORT unset defaults to 0, "5000" !== 0) the check passes incorrectly. This is also duplicated in handler.js.

Also, it explicitly disallows 1 port, which I think is fine, not sure why we would only ever have 1 port.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i was not super sure how to really validate this, I figured if we forget to set these they'd be the same like resolving as undefined. Ultimately I figured either the values match or there would be undefined === undefined.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!MIN_PORT || !MAX_PORT

The previous check would do this validation fine: !MIN_PORT || !MAX_PORT
As !undefined is true, !0 is true, etc, and !"string" or !Non-zero-int is false.

Comment thread handler/utils_h.js
export async function GetUnusedPort(MIN, MAX) {
// Generate the port list
const ports = [];
for (let port = MIN; port <= MAX; port++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think MIN and MAX are passed as strings to this function, meaning that something like "999" would be > "1000"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill add a Number cast just to be safe, I didn't anticipate that.

Comment thread handler/handler.js
for (const f of jail_conf.files) {
const requestedPath = path.normalize(f);
if (requestedPath.startsWith("/lib")) {
// @todo - This might need expanded to support other additions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes requested here, just curious what else we might expand to here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what other files we'd want to link directly from the host other than like libc.so.6, not sure if we'd want anything from say /etc or any other locations.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might depend on challenge implementation, I know this was something I used with my ssh challenges

@EnderHubris
EnderHubris marked this pull request as draft July 31, 2026 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants