feat(java): detect messaging ConnectionFactory constructed from a non-literal URL (SSRF, CWE-918) - #160
Open
ai-anant wants to merge 2 commits into
Conversation
…l in served HTML (CWE-79)
…al URL (SSRF, CWE-918)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a Java rule for Jenkins plugins (new java/jenkins/ssrf tree):
Pattern: a messaging connection factory (e.g.
JmsConnectionFactory/ActiveMQConnectionFactory/ any*ConnectionFactory) is instantiated with a non-literal URL and used to open an outbound broker connection. When that URL is derived from request, job-config, or other config/SCM-controlled data and no host allowlist is enforced, an attacker-influenced value makes the server open a connection to an arbitrary host/port — server-side request forgery (CWE-918).Rule:
codevigilant.java.jenkins.ssrf.connectionfactory.nonliteral-urlnew $FACTORY($URL);where $FACTORY matches*ConnectionFactory-style class names and $URL is an identifier/expression (metavariable-regex excludes string literals) — i.e. the sink where an untrusted value reaches a network connection.Validation:
semgrep --validatepasses. Fires on a positive repro(
new JmsConnectionFactory(uri);) and does not fire on the negative(
new JmsConnectionFactory("amqps://broker:5671");literal), confirming only non-literal (potentially untrusted) URLs are flagged.No plugin/project-specific details are included — this is the generic vulnerable code shape only.