Named query visibility scope and accidental public access in kdeneon
0 reputation · 01 Sept 2022, 11:41 UTC
0 reputation · 01 Sept 2022, 11:41 UTC
This question addresses the diagnosis of named query visibility scope within kdeneon's access‑control framework to prevent accidental public exposure. The supported feature is the Hibernate‑style named query definition, which enables static SQL reuse across sessions, and its interaction with kdeneon's permission model requires careful configuration.
Key constraints include version‑specific persistence of @NamedQuery mappings, where older releases may require explicit XML mapping, and the :name parameter binding syntax that prevents SQL injection but whose access‑control implications are not fully documented for kdeneon. Additionally, restricting query visibility to specific packages or XML mapping scopes may conflict with kdeneon's default public‑access defaults.
What access‑control mechanisms does kdeneon provide for named query visibility? How does the :name parameter binding syntax integrate with kdeneon's permission evaluation? Are there version‑dependent limitations on restricting query scope to internal packages?
33775 reputation · 01 Sept 2022, 12:15 UTC
kdeneon does not expose a native permission system for named query visibility. In the JPA/Hibernate ecosystem, a named query is registered once in a persistence unit (via @NamedQuery, @NamedQueries, or an orm.xml element). After registration, any code that has access to the EntityManager or Session can invoke it with createNamedQuery(\"queryName\"). The framework itself performs no visibility check, nor does it distinguish between "internal" and "public" packages.
The :name syntax is purely a query‑execution feature. It protects against SQL injection by binding a value to a named parameter, but it carries no permission semantics. kdeneon's permission evaluation, if any, will only be applied when the repository or service method that calls the named query is guarded by application‑level security (e.g., Spring Security @PreAuthorize).
JPA/Hibernate provide no mechanism to restrict a named query to a particular package or to mark it as private. The only scoping is the persistence unit itself. If you need to enforce that only code in certain packages can call a query, you must wrap the call in a service method that checks the caller's role or package, or you can expose the query through a repository interface that is annotated with security constraints.
org.hibernate.version or javax.persistence.version can be printed at runtime. Older releases (pre-2.0) relied more on XML, but the visibility behaviour is the same.@Service
public class UserService {
@PreAuthorize("hasRole('ADMIN')")
public List<User> findActiveUsers() {
return entityManager.createNamedQuery("User.findActive", User.class)
.getResultList();
}
}
EntityManager to untrusted code. Keep it inside beans that are subject to the security framework.orm.xml only; annotations (@NamedQuery) are standard since JPA 1.0 but are still fully supported.To tailor the recommendation more precisely, could you confirm whether kdeneon is an internal, proprietary framework that extends JPA/Hibernate, or if you are simply using the standard JPA stack? Knowing the exact framework version and any custom security extensions will help determine if additional, framework‑specific controls exist.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.