All posts
Liferay · 10 min read · Jun 19, 2026

Common security mistakes in Liferay customizations

Common security mistakes in Liferay customizations

Liferay ships with a mature security model: permission checkers, role-based access, a service layer that enforces entitlements, and parameterized persistence. Most vulnerabilities I find in custom code come from quietly stepping around that model rather than from any flaw in the platform itself. The pattern is almost always the same: a developer reaches for the convenient shortcut and skips the guardrail.

Skipping the permission check

The most common mistake is fetching an entity by id and rendering it without verifying the current user is allowed to see it. The local service layer (LocalServiceUtil) deliberately does not check permissions, while the remote service layer (ServiceUtil) does. Reaching for the local service in a portlet action because it is one line shorter is how data leaks across organizations and sites.

java
// Wrong: local service performs no permission check
Document doc = DLAppLocalServiceUtil.getFileEntry(fileEntryId);

// Right: use the permission-aware service, or check explicitly
Document doc = DLAppServiceUtil.getFileEntry(fileEntryId);

// Or guard the local call when you must use it
if (!permissionChecker.hasPermission(
        groupId, DLFileEntry.class.getName(), fileEntryId, ActionKeys.VIEW)) {
    throw new PrincipalException.MustHavePermission(userId, ActionKeys.VIEW);
}
Prefer the permission-aware service layer; check explicitly only when you genuinely need the local service.

The mistakes I see most often

MistakeWhy it is dangerousThe fix
Calling *LocalServiceUtil from a request handlerBypasses permission enforcement entirelyUse *ServiceUtil or check PermissionChecker
Building SQL with string concatenationSQL injection via user-supplied valuesUse parameterized queries / Dynamic Query
Echoing parameters into JSP/JS without escapingStored or reflected XSSHtmlUtil.escape / escapeJS on all output
Trusting hidden form fields and IDsForced browsing / IDORRe-validate ownership server-side
Secrets in source or portal-ext.propertiesCredential leak through the repoExternalize to a vault / env config
The handful of patterns behind most findings in a Liferay security review.

Never build SQL by hand

When a custom finder needs something beyond the generated Service Builder methods, the temptation is to concatenate a query string. Any user-controlled value in that string is a SQL injection waiting to happen. Use parameterized queries or Liferay's DynamicQuery API, which binds values safely.

java
// Wrong: user input concatenated straight into SQL
String sql = "SELECT * FROM MyEntity WHERE name = '" + name + "'";

// Right: DynamicQuery with a bound parameter
DynamicQuery query = DynamicQueryFactoryUtil.forClass(MyEntity.class)
    .add(RestrictionsFactoryUtil.eq("name", name));
List<MyEntity> results = myEntityLocalService.dynamicQuery(query);

Escape everything you render

Cross-site scripting still tops the list of real-world findings. Any value that originated from a user (a comment, a display name, a query parameter reflected back) must be escaped at the point of output. Liferay gives you HtmlUtil.escape for HTML context and HtmlUtil.escapeJS for values dropped into a script block. Escaping on input is not enough; escape on output, in the context where the value lands.

Keep secrets out of the build

Database passwords, API keys, and signing secrets committed to the repository are the breach that keeps giving, because they survive in git history long after someone rotates the live value. Externalize them into environment configuration or a secrets manager, and reference them at runtime. Treat portal-ext.properties in version control as a red flag in code review.

Make the safe path the easy path

Security mistakes are rarely the result of ignorance; they are the result of friction. If using the permission-aware service is harder than the local one, people will choose the local one under deadline pressure. Wrap the correct patterns in small shared helpers, add a few static-analysis rules for the obvious offenders, and put a permission-and-injection checklist into every pull request. The goal is a codebase where doing the secure thing is also the path of least resistance.

Contact

Let’s connect

Have a Liferay or Backend project you’d like to talk through? Fill in the form and I’ll get back to you.

Book Calendar