Skip to content

Potential fix for code scanning alert no. 3: Server-side request forgery - #49

Draft
jimklimov wants to merge 4 commits into
masterfrom
alert-autofix-3
Draft

Potential fix for code scanning alert no. 3: Server-side request forgery#49
jimklimov wants to merge 4 commits into
masterfrom
alert-autofix-3

Conversation

@jimklimov

@jimklimov jimklimov commented Aug 5, 2026

Copy link
Copy Markdown
Member

Potential fix for https://github.com/networkupstools/jNut/security/code-scanning/3

To fix this without changing intended behavior more than necessary, validate the server path parameter against a strict server-side allowlist before any connection attempt. The best location is NutRestProvider.Server(String server) because it is the trust boundary entry-point and already parses host/port.

Implement:

  • A static allowlist of permitted UPSD hostnames/IPs in NutRestProvider.
  • A helper method that validates host membership in the allowlist.
  • In the Server constructor, after parsing host (or using whole server when no port given), reject non-allowed hosts with IllegalArgumentException.
  • Keep existing port parsing/fallback behavior unchanged.

This preserves current functionality for approved hosts while preventing attacker-controlled arbitrary destinations.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

TODO: This would want a config file or CLI argument support to add permitted hosts on the fly. API to do so is here.

Implement a Set of allowed UPSD host name strings, reject requests to DoS unpermitted systems

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@jimklimov jimklimov added bug java Pull requests that update java code labels Aug 5, 2026
Allow adding/removing/listing entries in the Set of permitted hosts to talk to
@jimklimov
jimklimov marked this pull request as ready for review August 5, 2026 17:10
@jimklimov
jimklimov marked this pull request as draft August 5, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug java Pull requests that update java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant