Skip to content

Added notes about XSS when using URIFragments directly #4416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion articles/framework/advanced/advanced-urifu.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public class MyUI extends UI {
}

void enter(String fragment) {
// it is good practice to not use the fragment directly but to sanitize it first
// since it can be set by the user
... initialize the UI ...
}
}
Expand Down Expand Up @@ -155,7 +157,7 @@ public class MyCustomServlet extends VaadinServlet
Writer writer = response.getWriter();
writer.append("<html><body>"+
"<p>Here is some crawlable "+
"content about " + fragment + "</p>");
"content about " + sanitizeHtmlFragment(fragment) + "</p>");

// A list of all crawlable pages
String items[] = {"mercury", "venus",
Expand All @@ -172,6 +174,11 @@ public class MyCustomServlet extends VaadinServlet
} else
super.service(request, response);
}

private String sanitizeHtmlFragment(String s){
// return a String that is safe to use in HTML
... implementation ...
}
}
----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ page.addUriFragmentChangedListener(new UriFragmentChangedListener() {
});
....

Note: HTML is disabled by default in Notifications, but can be enabled with
[methodname]#setHtmlContentAllowed(true)#. When enabled, you can use any HTML
markup in the caption and description of a notification. If it is in any way
possible to get the notification content from user input, you should either
disallow HTML or sanitize the content carefully, as noted in
<<../advanced/advanced-security#advanced.security.sanitizing,"Sanitizing
User Input to Prevent Cross-Site Scripting">>.

You can access client browser details:

[source,java]
Expand Down