Skip to content

Preserve root path when stripping trailing slash for -noslash - #916

Closed
MRX-72 wants to merge 1 commit into
sullo:mainfrom
MRX-72:fix/noslash-root-path
Closed

MRX-72 wants to merge 1 commit into
sullo:mainfrom
MRX-72:fix/noslash-root-path

Conversation

@MRX-72

@MRX-72 MRX-72 commented Oct 4, 2026

Copy link
Copy Markdown

Summary

-noslash is documented as stripping a trailing slash, e.g. /admin/ → /admin. The implementation used a bare s/\/$//, which also turns the root path / into an empty string.

# program/plugins/nikto_core.plugin
$request{'whisker'}->{'uri'} =~ s/\/$// if ($CLI{'noslash'});

For a request to /, the URI becomes "". That empty URI normally survives only because LW2::http_fixup_request() rewrites an empty URI back to / — but that fixup is skipped on the noclean request path (...http_fixup_request(\%request) unless ($flags->{'noclean'})), which would leave a malformed request line.

Fix

Use a lookbehind so the trailing slash is removed only when another character precedes it. / is left untouched; /admin/ still becomes /admin.

$request{'whisker'}->{'uri'} =~ s{(?<=.)/$}{} if ($CLI{'noslash'});

Verification

$ perl -e 'for my $u ("/", "/admin/", "/a/b/", "//", "/foo", "") {
    (my $old = $u) =~ s/\/$//;
    (my $new = $u) =~ s{(?<=.)/$}{};
    printf "%-10s old=%-8s new=%-8s\n", $u, "\x27$old\x27", "\x27$new\x27"; }'
/          old=''       new='/'
/admin/    old='/admin' new='/admin'
/a/b/      old='/a/b'   new='/a/b'
//         old='/'      new='/'
/foo       old='/foo'   new='/foo'
           old=''       new=''

$ perl -c program/plugins/nikto_core.plugin
program/plugins/nikto_core.plugin syntax OK

$ cd program && perl nikto.pl -dbcheck -nolookup   # core loads/runs clean

-noslash strips a trailing slash so '/admin/' is requested as '/admin'.
Applied as a bare s/\/$// it also turns the root path '/' into an empty
string. That empty URI normally survives only because
http_fixup_request() rewrites it back to '/', but that fixup is skipped
on the 'noclean' request path, which would leave a malformed request
line.

Use a lookbehind so the slash is removed only when another character
precedes it: '/' is left untouched while '/admin/' still becomes
'/admin'.
@digininja

digininja commented Oct 4, 2026 via email

Copy link
Copy Markdown
Contributor

@MRX-72
MRX-72 marked this pull request as ready for review October 4, 2026 17:19
@MRX-72

MRX-72 commented Oct 4, 2026

Copy link
Copy Markdown
Author

@sullo when you get a chance, this is a small one-line fix: -noslash turns the root path / into an empty URI (bare s/\/$//), which only survives because http_fixup_request() rewrites it back — and that's skipped on the noclean path. The lookbehind leaves / intact while /admin/ still becomes /admin. Rationale and verification are in the description. Thanks for taking a look!

@MRX-72

MRX-72 commented Oct 4, 2026

Copy link
Copy Markdown
Author

honestly just spotted it reading through the code, wasn't chasing a crash or anything. -noslash ends up turning / into an empty string which kind of defeats the point of the option. most of the time you won't notice because http_fixup_request resets empty back to /, but that bit gets skipped on the noclean path so it can leak through there. felt like a cheap one liner to fix so figured why not. no worries if you reckon it's too edge casey, happy to close it.

@digininja

digininja commented Oct 4, 2026 via email

Copy link
Copy Markdown
Contributor

@sullo

sullo commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Good catch, thanks for reporting/fixing. I've merged it into pre-release as 2b17abe and will get out in the next release which is 1-2 weeks out.

@sullo sullo closed this Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants