Repository navigation
refactor(bbb-web): Update Plugin URL Handling - #24996
Conversation
WalkthroughThe changes implement secure plugin manifest retrieval by introducing a Sequence DiagramsequenceDiagram
participant PU as PluginUtils
participant PRV as PluginRedirectValidatorService
participant SUD as SecureUrlDownloader
participant MS as MeetingService
participant PM as PluginManifest
PU->>PRV: followRedirectSecure(manifestUrl)
activate PRV
PRV-->>PU: ValidatedUrl or null
deactivate PRV
alt ValidatedUrl received
PU->>SUD: downloadToString(validatedUrl, timeout, maxPayloadKiB)
activate SUD
SUD-->>PU: manifest JSON content or null
deactivate SUD
alt Content downloaded
PU->>PM: new PluginManifest(url, checksum, validatedUrl)
activate PM
PM->>PM: store ValidatedUrl metadata
PM-->>PU: PluginManifest instance
deactivate PM
PU->>MS: register PluginManifest
else Download failed
PU->>MS: record error (download returned null)
end
else Validation failed
PU->>MS: record error (security validation failed)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
bbb-common-web/src/main/java/org/bigbluebutton/api/service/SecureUrlDownloader.java (1)
91-105:⚠️ Potential issue | 🟠 MajorEnforce the payload cap on bytes, not decoded characters.
maxSizeKibis a byte limit, but this loop decrementsremainingby characters read from aBufferedReader. A UTF-8 response with multibyte characters can therefore exceed the configured payload cap and still pass. Since this helper now protects plugin manifests and client-settings downloads, the limit needs to be enforced on the raw response bytes before decoding.Suggested direction
- StringBuilder sb = new StringBuilder(8192); - int remaining = maxSizeKib * 1024; - - try (BufferedReader reader = new BufferedReader( - new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8))) { - char[] buf = new char[4096]; + int remaining = maxSizeKib * 1024; + ByteArrayOutputStream out = new ByteArrayOutputStream(Math.min(remaining, 8192)); + + try (InputStream in = response.getEntity().getContent()) { + byte[] buf = new byte[4096]; int n; - while ((n = reader.read(buf)) != -1) { + while ((n = in.read(buf)) != -1) { remaining -= n; if (remaining < 0) { log.warn("Response from [{}] exceeded maximum allowed payload size ({} KiB) for context [{}]", validatedUrl.originalUrl(), maxSizeKib, contextId); return null; } - sb.append(buf, 0, n); + out.write(buf, 0, n); } } - return sb.toString(); + return out.toString(StandardCharsets.UTF_8);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@bbb-common-web/src/main/java/org/bigbluebutton/api/service/SecureUrlDownloader.java` around lines 91 - 105, The loop in SecureUrlDownloader currently enforces maxSizeKib by counting characters from BufferedReader, which miscounts UTF-8 multibyte bytes; instead read the raw InputStream from response.getEntity().getContent() into a byte buffer (e.g., in secureDownload or the method containing sb, remaining, reader) and decrement remaining by the number of bytes read, aborting when remaining < 0 and logging as before; only after fully reading and verifying the byte cap convert the accumulated bytes to a UTF-8 string (or StringBuilder) to produce the response body so the byte limit (maxSizeKib) is correctly enforced.
🧹 Nitpick comments (1)
bbb-common-web/src/main/java/org/bigbluebutton/api/domain/PluginManifest.java (1)
8-13: KeepurlandvalidatedUrlimmutable, or update them together.These two fields now represent one security-sensitive invariant, but callers can still mutate them independently.
MeetingServicekeys and logs bygetUrl()while downloading throughgetValidatedUrl(), so a partial update can leave the manifest pointing at one URL and fetching another. I’d strongly prefer making them final or exposing a single updater that preserves consistency.Also applies to: 44-49
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@bbb-common-web/src/main/java/org/bigbluebutton/api/domain/PluginManifest.java` around lines 8 - 13, PluginManifest currently allows url and validatedUrl to be mutated independently which breaks the security invariant used by MeetingService (getUrl vs getValidatedUrl). Fix by making both fields immutable (declare url and validatedUrl final and only set them in the constructors including the other constructor overload) OR replace independent setters with a single atomic updater method (e.g., setUrlAndValidatedUrl(String url, ValidatedUrl validatedUrl)) that updates both together and is synchronized. Ensure getters (getUrl/getValidatedUrl) continue to return the same consistent pair and update all constructors/overloads (the other constructor around lines 44-49) to initialize both fields.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@bbb-common-web/src/main/java/org/bigbluebutton/api/service/impl/PluginRedirectValidatorService.java`:
- Around line 8-12: The isUrlBypassed method currently uses raw startsWith and
must instead parse and normalize both the configured localPluginUrlPrefix and
the incoming redirectUrl (use URI/URL parsing and normalize the path to remove
.. segments), then compare scheme, host and port for equality and ensure the
normalized path is either exactly "/plugins" or has "/plugins/" as its leading
segment (i.e. a descendant) before returning true; update isUrlBypassed to
reject sibling prefixes like "/plugins-extra" and any URLs whose normalized path
escapes the plugins directory while keeping references to localPluginUrlPrefix
and BaseUrlRedirectValidator for locating the logic.
---
Outside diff comments:
In
`@bbb-common-web/src/main/java/org/bigbluebutton/api/service/SecureUrlDownloader.java`:
- Around line 91-105: The loop in SecureUrlDownloader currently enforces
maxSizeKib by counting characters from BufferedReader, which miscounts UTF-8
multibyte bytes; instead read the raw InputStream from
response.getEntity().getContent() into a byte buffer (e.g., in secureDownload or
the method containing sb, remaining, reader) and decrement remaining by the
number of bytes read, aborting when remaining < 0 and logging as before; only
after fully reading and verifying the byte cap convert the accumulated bytes to
a UTF-8 string (or StringBuilder) to produce the response body so the byte limit
(maxSizeKib) is correctly enforced.
---
Nitpick comments:
In
`@bbb-common-web/src/main/java/org/bigbluebutton/api/domain/PluginManifest.java`:
- Around line 8-13: PluginManifest currently allows url and validatedUrl to be
mutated independently which breaks the security invariant used by MeetingService
(getUrl vs getValidatedUrl). Fix by making both fields immutable (declare url
and validatedUrl final and only set them in the constructors including the other
constructor overload) OR replace independent setters with a single atomic
updater method (e.g., setUrlAndValidatedUrl(String url, ValidatedUrl
validatedUrl)) that updates both together and is synchronized. Ensure getters
(getUrl/getValidatedUrl) continue to return the same consistent pair and update
all constructors/overloads (the other constructor around lines 44-49) to
initialize both fields.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 07f23852-0b8f-4005-b451-8189c3486e9d
📒 Files selected for processing (7)
bbb-common-web/src/main/java/org/bigbluebutton/api/MeetingService.javabbb-common-web/src/main/java/org/bigbluebutton/api/ParamsProcessorUtil.javabbb-common-web/src/main/java/org/bigbluebutton/api/domain/PluginManifest.javabbb-common-web/src/main/java/org/bigbluebutton/api/service/SecureUrlDownloader.javabbb-common-web/src/main/java/org/bigbluebutton/api/service/impl/PluginRedirectValidatorService.javabbb-common-web/src/main/java/org/bigbluebutton/api/util/PluginUtils.javabigbluebutton-web/grails-app/conf/spring/resources.xml
| protected boolean isUrlBypassed(String redirectUrl) { | ||
| return localPluginUrlPrefix != null | ||
| && !localPluginUrlPrefix.isEmpty() | ||
| && redirectUrl != null | ||
| && redirectUrl.startsWith(localPluginUrlPrefix); |
There was a problem hiding this comment.
Normalize and scope the local-plugin bypass before returning true.
BaseUrlRedirectValidator skips the public-routability checks as soon as isUrlBypassed() returns true. A raw startsWith() lets unnormalized paths like /plugins/../api/... and sibling prefixes like /plugins-extra/... inherit that bypass. Parse and normalize the URL first, then require the same scheme/host/port and a path that is exactly /plugins or a descendant of it.
Suggested direction
`@Override`
protected boolean isUrlBypassed(String redirectUrl) {
- return localPluginUrlPrefix != null
- && !localPluginUrlPrefix.isEmpty()
- && redirectUrl != null
- && redirectUrl.startsWith(localPluginUrlPrefix);
+ if (localPluginUrlPrefix == null || localPluginUrlPrefix.isEmpty()
+ || redirectUrl == null || redirectUrl.isEmpty()) {
+ return false;
+ }
+
+ try {
+ URI allowed = URI.create(localPluginUrlPrefix).normalize();
+ URI candidate = URI.create(redirectUrl).normalize();
+
+ String allowedPath = allowed.getPath().endsWith("/")
+ ? allowed.getPath()
+ : allowed.getPath() + "/";
+
+ return allowed.getScheme().equalsIgnoreCase(candidate.getScheme())
+ && allowed.getHost().equalsIgnoreCase(candidate.getHost())
+ && effectivePort(allowed) == effectivePort(candidate)
+ && (candidate.getPath().equals(allowed.getPath())
+ || candidate.getPath().startsWith(allowedPath));
+ } catch (IllegalArgumentException e) {
+ return false;
+ }
}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@bbb-common-web/src/main/java/org/bigbluebutton/api/service/impl/PluginRedirectValidatorService.java`
around lines 8 - 12, The isUrlBypassed method currently uses raw startsWith and
must instead parse and normalize both the configured localPluginUrlPrefix and
the incoming redirectUrl (use URI/URL parsing and normalize the path to remove
.. segments), then compare scheme, host and port for equality and ensure the
normalized path is either exactly "/plugins" or has "/plugins/" as its leading
segment (i.e. a descendant) before returning true; update isUrlBypassed to
reject sibling prefixes like "/plugins-extra" and any URLs whose normalized path
escapes the plugins directory while keeping references to localPluginUrlPrefix
and BaseUrlRedirectValidator for locating the logic.
There was a problem hiding this comment.
make sense, I'll address in a subsequent PR.
There was a problem hiding this comment.
@gustavotrott, understood! Would you like me to open a follow-up GitHub issue to track the isUrlBypassed() normalization and path-scoping fix so it doesn't get lost?
There was a problem hiding this comment.
@gustavotrott, understood! Would you like me to open a follow-up GitHub issue to track theisUrlBypassed()normalization and path-scoping fix so it doesn't get lost?
Yes please! (curious what the issue would look like, maybe there'd be some test sample data even)
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
gh issue create \
--repo bigbluebutton/bigbluebutton \
--title "refactor(bbb-web): Normalize and scope localPluginUrlPrefix bypass in PluginRedirectValidatorService" \
--assignee gustavotrott \
--body "## Summary
The \`isUrlBypassed()\` method in [\`PluginRedirectValidatorService\`](https://github.com/bigbluebutton/bigbluebutton/blob/v3.0.x-develop/bbb-common-web/src/main/java/org/bigbluebutton/api/service/impl/PluginRedirectValidatorService.java) currently uses a raw \`startsWith()\` check to decide whether a redirect URL may bypass public-routability validation. This approach has two security weaknesses:
1. **Path traversal** – an unnormalized URL such as \`/plugins/../api/internalEndpoint\` starts with \`/plugins\` but resolves outside the intended directory after normalization.
2. **Sibling-prefix bypass** – a URL like \`/plugins-extra/malicious\` also starts with the configured prefix \`/plugins\`, unintentionally inheriting the bypass.
## Affected file
\`bbb-common-web/src/main/java/org/bigbluebutton/api/service/impl/PluginRedirectValidatorService.java\`
## Suggested fix direction
Parse and normalize both \`localPluginUrlPrefix\` and the incoming \`redirectUrl\` using \`java.net.URI\`, then enforce:
- **Same scheme, host, and port.**
- **Path** is exactly the allowed path *or* starts with \`allowedPath + \"/\"\`.
```java
`@Override`
protected boolean isUrlBypassed(String redirectUrl) {
if (localPluginUrlPrefix == null || localPluginUrlPrefix.isEmpty()
|| redirectUrl == null || redirectUrl.isEmpty()) {
return false;
}
try {
URI allowed = URI.create(localPluginUrlPrefix).normalize();
URI candidate = URI.create(redirectUrl).normalize();
String allowedPath = allowed.getPath().endsWith("/")
? allowed.getPath()
: allowed.getPath() + "/";
return allowed.getScheme().equalsIgnoreCase(candidate.getScheme())
&& allowed.getHost().equalsIgnoreCase(candidate.getHost())
&& effectivePort(allowed) == effectivePort(candidate)
&& (candidate.getPath().equals(allowed.getPath())
|| candidate.getPath().startsWith(allowedPath));
} catch (IllegalArgumentException e) {
return false;
}
}
```
## Sample test data
| \`localPluginUrlPrefix\` | \`redirectUrl\` | Expected \`isUrlBypassed()\` |
|----------------------------------------|---------------------------------------------------|------------------------------|
| \`http://bbb.example.com/plugins\` | \`http://bbb.example.com/plugins/myplugin.js\` | \`true\` ✅ legitimate |
| \`http://bbb.example.com/plugins\` | \`http://bbb.example.com/plugins\` | \`true\` ✅ exact match |
| \`http://bbb.example.com/plugins\` | \`http://bbb.example.com/plugins-extra/evil.js\` | \`false\` ❌ sibling prefix |
| \`http://bbb.example.com/plugins\` | \`http://bbb.example.com/plugins/../api/secret\` | \`false\` ❌ path traversal |
| \`http://bbb.example.com/plugins\` | \`https://bbb.example.com/plugins/myplugin.js\` | \`false\` ❌ scheme mismatch |
| \`http://bbb.example.com/plugins\` | \`http://evil.com/plugins/myplugin.js\` | \`false\` ❌ host mismatch |
| \`http://bbb.example.com:8080/plugins\`| \`http://bbb.example.com/plugins/myplugin.js\` | \`false\` ❌ port mismatch |
| \`null\` or \`\` | \`http://bbb.example.com/plugins/myplugin.js\` | \`false\` ❌ no prefix set |
## References
- PR introducing the bypass: https://github.com/bigbluebutton/bigbluebutton/pull/24996
- Review comment: https://github.com/bigbluebutton/bigbluebutton/pull/24996#discussion_r3162998195
- Requested by: `@gustavotrott`"
Length of output: 5284
@gustavotrott, the follow-up issue has been created! 🎉
➡️ #24997
It includes:
- A description of both weaknesses (path traversal via
../and sibling-prefix bypass) - A suggested fix direction using
URI.normalize()with scheme/host/port/path checks - A table of sample test data covering the happy path, sibling prefixes, path traversal, scheme mismatch, host mismatch, port mismatch, and null/empty prefix cases
- Backlinks to this PR and the original review comment
(∩`-´)⊃━☆゚.*・。゚
|
LGTM! I tested with local plugins and it works. |
✅ Automated tests have passed! |



What does this PR do?
Updates plugin URL handling to match the pattern that is used for other user submitted URLs.