Moqui Framework

repository·master·Indexed 43 days ago

https://github.com/moqui/moqui-framework

An enterprise-grade framework for building complex, data-driven applications, providing core business logic and service orchestration capabilities. Version 4.0.0 introduces requirements for Java 21, Groovy 5, Gradle 9.2, and a migration from javax to jakarta EE 11 namespaces.

Tokens
13.9K
Snippets
29
Records
73
Agent score
56%

What's inside Moqui

  1. Overview of Moqui Framework

    master

    Moqui Framework is a comprehensive framework designed for building enterprise-grade applications. It provides a robust set of features for business logic, data management, and service orchestration.

    Key resources for developers:

  2. Review Moqui security controls and OWASP compliance

    master

    Moqui Framework implements a wide range of security controls mapped to OWASP categories. Key areas of protection include:

    • Access Control (A01): Restricts unauthenticated tools, enforces VIEW-only permissions (preventing Service Run, cache clear, data import/export, etc.), and protects REST endpoints (/rest/s1, /rest/e1) and WebSocket handshakes.
    • Misconfiguration (A02): Enforces default CSP, X-Frame-Options, and nosniff headers. Manages CORS via allow-origins, enforces HttpOnly and SameSite=Lax session cookies, and disables dangerous factories like SubEtha SMTP by default.
    • Cryptographic Failures (A04): Uses SHA-256 for password hashing and requires operators to override the default entity_ds_crypt_pass (which is CHANGEME).
    • Injection (A05): Provides allow-html service parameters (none, safe, any) to validate or strip markup and protects against SQL injection by treating SQL-looking values as data.
    • Authentication (A07): Implements failed-login lockout, prevents account enumeration via generic error messages, enforces CSRF protection on POST requests, and manages MFA (single-use codes).
    • Integrity (A08): Protects against Zip-Slip attacks and XML External Entity (XXE) expansion in MNode.parse.
    • Logging & Monitoring (A09): Maintains login history while ensuring passwords are not stored in logs.
    • Error Handling (A10): Prevents leaking Java stack traces on unknown paths and HTML-escapes error messages to prevent injection.
  3. Implement sub-selects in view-entities

    master

    Moqui 2.1.0 introduced support for sub-selects (sub-queries) within view-entity definitions. This allows for more complex join logic and functional flexibility.

    How to use:

    • Enable sub-selects by adding a flag to a member-entity or member-relationship element.
    • The query structure changes so the member entity is joined in a SELECT clause. Conditions for fields on the member entity are placed in its own WHERE clause rather than the top-level WHERE clause.
    • You can use alias.@function and alias.complex-alias (e.g., using concat_ws for combined name aliases) within the sub-select.
    • Sub-selects are supported even when the member is another view-entity.
  4. Understand Moqui's designed security exposures

    master

    Some Moqui defaults are intentionally permissive to allow specific functionality, but they should be reviewed by operators:

    • Groovy Shell WebSocket: The /groovysh endpoint is enabled by default. It allows Remote Code Execution (RCE) but is gated by ADMIN_ADV and GROOVY_SHELL_WEB permissions.
    • Password Reset: The reset#Password transition is configured with authenticate="anonymous-all" and allow-remote="true" to allow remote password resets.
    • Email Allowed Hosts: The email_allowed_hosts setting is empty by default, meaning the system may connect to any host for polling/sending until an operator defines an allow-list.
    • DataSnapshot Import: Defaults to disableEntityEca="true" so that an update via Tools can restore security-critical rows.
  5. Identify privileged Tools and System screens

    master

    Moqui provides powerful administrative screens that are intentionally privileged. Access is typically controlled via the ADMIN or ADMIN_ADV groups.

    Tools (/qapps/tools, /apps/tools, /vapps/tools)

    These screens allow high-impact operations:

    • Groovy Shell: Provides RCE in the JVM (requires GROOVY_SHELL_WEB + AUTHZA_ALL).
    • SQL Runner: Arbitrary SQL execution (requires SQL_RUNNER_WEB + AUTHZA_ALL).
    • Entity Data Import/Export: Bulk entity writes/reads. Note that identity-admin and secret-config entities are refused for safety.
    • Service Run: Call any authorized service by name.

    System (/qapps/system, ...)

    These screens manage the framework's core operations:

    • Security: Administration of users, groups, and MFA.
    • Resource / ElFinder: File management. In production, write commands to component:// or file: roots are refused.
    • Service Jobs: Management of scheduled jobs.
    • System Messages: Queue and consume messages (paired with /rest/sm).
    • Entity Sync: Data replication.
    • Operational Tools: Cache, Log Viewer, Audit Log, and Active Users.
  6. Use absolute paths for moqui.conf

    master
    When configuring the moqui.conf property (via system property, command line, or MoquiInit.properties), if the path starts with a forward slash (/), Moqui treats it as an absolute path rather than a path relative to the runtime directory. This allows you to host the configuration file outside the runtime directory.
  7. Using ElasticFacade for Search (v3.0.0+)

    master

    In Moqui 3.0.0 and later, the embedded moqui-elasticsearch component is no longer supported. It has been replaced by ElasticFacade, which acts as a client to an external OpenSearch or Elasticsearch instance.

    To use it, you must install an external instance in runtime/opensearch or runtime/elasticsearch. These can be automatically managed (started/stopped) by the MoquiStart class if running as an executable WAR.

    Recommended versions for v3.0.0:

    • OpenSearch 1.3.1
    • Elasticsearch 7.10.2 (the last Apache 2.0 licensed version)
  8. Use the Tool Factory to manage tool instances

    master

    Moqui 2.0.0 introduced the org.moqui.context.ToolFactory interface to initialize, destroy, and retrieve instances of tools (like ElasticSearch, Camel, or KIE).

    To use tools, you should interact with them via the ExecutionContext or ExecutionContextFactory rather than accessing them directly.

    Configuration: You can define tools in your MoquiConf.xml using the tools.tool-factory element. Components can also provide their own MoquiConf.xml to modify the tool factory.

    // Using ExecutionContext to get a tool
    Tool myTool = ec.getTool("ElasticSearch", Client.class);
    
    // Using ExecutionContextFactory
    Tool myTool = ecfi.getTool("Camel", CamelContext.class);
  9. Use DataDocument to create dynamic view entities

    master

    In Moqui 2.1.0+, you can use DataDocument to create dynamic view entities. This allows for flexible, data-driven query definitions.

    Key behaviors:

    • Any DataDocument can be treated as an entity using the naming pattern DataDocument.${dataDocumentId}.
    • DataDocumentField supports a functionName attribute for applying functions to fields within a DataDocument based query.
    • Note on Primary Keys: For version 2.1.0, DataDocument JSON generation no longer automatically adds all primary key fields of the primary entity to allow for aggregation. If you are using these for ElasticSearch indexing, you must explicitly define all primary key fields to ensure a unique ID is present.
    <!-- Example naming pattern for accessing a DataDocument as an entity -->
    DataDocument.my_custom_document_id
  10. Use 'no sub-path' subscreens for screen overrides

    master

    Moqui supports 'no sub-path' subscreens. This mechanism allows you to extend or override screens, transitions, and resources under a parent screen by searching for a specific path in each 'no sub-path' subscreen first. If the path is not found there, the system falls back to looking under the parent screen.

    This is useful for resolving paths like /index.html or /Login to specific components (e.g., moqui-org) rather than defaulting to the standard webroot definitions.

  11. Configure Multi-Factor Authentication (MFA)

    master

    Moqui 3.0.0 introduced MFA support for logins, password updates in screens, and REST APIs.

    Supported Factors:

    • authc code via email or SMS
    • TOTP code (via authenticator apps)
    • Backup codes

    Configuration: You can enforce MFA by setting a flag on a UserGroup. If the flag is enabled, all users in that group will be required to provide a second factor if they have any additional factor enabled.

  12. Authenticate WebSocket handshakes

    master

    When establishing a WebSocket connection, Moqui 4.0.1 no longer supports authentication via the query string (e.g., ?api_key=... or ?login_key=...).

    To authenticate a WebSocket handshake, you must use one of the following:

    1. An existing HTTP session (via session cookie).
    2. HTTP Basic authentication.
    3. api_key or login_key provided in the headers.

    If you previously relied on passing keys in the URL for endpoints like /groovysh, you must update your client to send these as headers.