<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jvandekamp on Medium]]></title>
        <description><![CDATA[Stories by Jvandekamp on Medium]]></description>
        <link>https://medium.com/@jvandekamp?source=rss-b74ffd52a911------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Tun-lYFsneWtE93G</url>
            <title>Stories by Jvandekamp on Medium</title>
            <link>https://medium.com/@jvandekamp?source=rss-b74ffd52a911------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:18:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jvandekamp/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Securing Your Mendix App]]></title>
            <link>https://medium.com/@jvandekamp/securing-your-mendix-app-9ec22ca23af9?source=rss-b74ffd52a911------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ec22ca23af9</guid>
            <dc:creator><![CDATA[Jvandekamp]]></dc:creator>
            <pubDate>Tue, 08 Oct 2024 16:38:39 GMT</pubDate>
            <atom:updated>2024-10-08T16:38:39.883Z</atom:updated>
            <content:encoded><![CDATA[<p>In Mendix, ensuring that data is properly validated is critical for maintaining both application security and data integrity. This article will explore common pitfalls in entity validation and present three robust methods for securing your application..</p><p>There are many topics around Mendix security. This article focuses on the importance of validating your entities. We’ll look at a simple case here, although in real-world applications, these scenarios are often more complex.</p><p>Let’s say we have an entity called Animal, and we want only objects with a name starting with a capital ‘L’ to be entered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/185/0*_b0b4W_Qs5w5DOpN" /></figure><p>We let Mendix generate the overview pages, then we end up with something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/203/0*vzkpl6ebSD72NGIj" /></figure><p>If we run this, there is no validation at all. Let’s add some validation.</p><p>Now we have a validation flow that looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*vEvwRLZNIarxD_lh" /></figure><p>When we try to add an animal whose name doesn’t start with the letter “L,” we get a helpful error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/0*gpyup0WW4mbgOkzz" /></figure><p>So, we’ve secured our application, and we’re only allowed to enter animals whose names start with the letter “L.” But is there a catch?</p><p>Using the Mendix client API, we can also create or edit objects. Let’s try that in the console of the browser:</p><pre>mx.data.create({<br>    entity: &quot;Part2.Animal&quot;,<br>    callback: function(mxObject) {<br>        //set attribute<br>        mxObject.set(&quot;StartWithL&quot;, &quot;Elephant&quot;);<br>        console.log(&quot;Object created&quot;);<br>        mx.data.commit({<br>            mxobj: mxObject,<br>            callback: function(){<br>                console.log(&quot;Object committed&quot;);<br>            },<br>            error: function(error){<br>                console.log(&quot;Could not commit object:&quot;, error);<br>            }<br>        })<br>    },<br>    error: function(error) {<br>        console.log(&quot;Could not create object:&quot;, e);<br>    }<br>});</pre><p>If we take a look in the app, we see the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/0*t5lxviLKBPHBY0Tl" /></figure><p>We’ve created an object with an animal that doesn’t start with an “L.” What’s going on here?</p><p>Let’s examine the domain model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/0*DR2c_eXMQW1KRuDn" /></figure><p>As you can see, the User role has read and write access to the StartWithL attribute. Which means the user can change this attribute using the client API. Adding validation behind a button is not sufficient for proper security.</p><p>I will explain three methods for correctly implementing effective validation.</p><ol><li>Use before commit validation</li><li>Use a non-persistent entity</li><li>Use a custom JAVA before commit check</li></ol><h3><strong>1. Use Before Commit Validation</strong></h3><p>Let’s add the “before commit” handler.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/0*yrZoDqHzpxxX8oXR" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/0*SA2mfBnMFWCZKUaS" /></figure><p>If we try our JavaScript again, we get an error message, so this approach works.</p><p>In this simple case, it will work well. However, in more complex cases, you may need additional context, and there could be many more checks requiring different conditions. Implementing this can become a significant effort in such cases.</p><h3><strong>2. Use a Non-Persistent Entity</strong></h3><p>Another option is using a non-persistent entity. Here, we change the entity so that the user doesn’t need write access to the attribute. Our JavaScript client action will no longer work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/0*YiNczkKMMLt0vVb5" /></figure><p>We also create a non-persistent copy of the entity, associating it with the original entity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/0*dzXG1VhV714yWwqb" /></figure><p>All user interactions with the Animal entity must be done through the non-persistent entity:</p><ul><li>When creating a new object, create the non-persistent entity first.</li><li>When editing an object, copy the attribute values to the non-persistent entity and open it.</li><li>On save, perform validation on the non-persistent entity. If valid, create or modify the actual object.</li></ul><p>The following actions handle this process:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/0*lzJbgCMRQAhM5OPI" /><figcaption>1) ACT_Animal_New</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/0*PcTETNbUW7UKSMEh" /><figcaption>2) ACT_Animal_Edit</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CA6CJ43BJX-57bm_" /><figcaption>3) ACT_Animal_Save</figcaption></figure><p>This method also works but can be a lot of work and may have a significant impact on the application.</p><h3><strong>3. Use a Custom JAVA Before Commit Check</strong></h3><p>I’d like to introduce an alternative way to prevent changes to the Animal entity. This method uses a Java action before the commit. The action checks whether attributes have changed that are not specified in a new attribute called “AllowedToChange.” If changes are detected in attributes not specified, the Java action will return an error.</p><p>This means that all commits in Mendix should contain a list of attribute names separated by a semicolon (;).</p><p>Here’s the setup:</p><ol><li>Create an attribute (“AllowedToChange”) with no rights for users.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/0*SS_gaVNhqoxGtBOg" /></figure><ol><li>A before commit microflow which runs the JAVA action.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/0*Xxhgas6837bRlaZ3" /></figure><ol><li>An extra Change Object Action to specify which attributes are allowed to change.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ez-BhHFa4wm_ueqY" /></figure><p>Now, if we try the JavaScript again, we get an error in the browser console, and we also see detailed logging in Mendix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/376/0*XR5WU6WaKvk85mYe" /></figure><p>This introduces a safer and simpler method for implementing validation. The advantage is that it has the least impact on your app. The disadvantage is that it’s not a standard Mendix solution. You have to specify the list of attributes manually, and the attribute names aren’t automatically updated if their names change, which means the “find usages” feature in Studio Pro won’t work.</p><p>I hope that Mendix will offer this kind of functionality out of the box in the future.</p><p>If you’re interested in the module that performs the checks, it will be available on the marketplace. I’m waiting for approval.</p><p>In the meantime The Mendix project containing all the cases above can be downloaded <a href="https://github.com/StoneworxNL/Mendix-AttributeLock">here</a>.</p><h3>Conclusion</h3><p>To sum up, proper validation in Mendix is essential for ensuring both data integrity and security. The three methods outlined above provide different ways to achieve this, depending on the complexity of your application and the level of security required.</p><p>If you’ve faced similar validation challenges or have other security tips for Mendix users, I’d love to hear your thoughts in the comments! And if you have any concerns about the security of your Mendix app, feel free to reach out to me, and we can schedule a security assessment of your application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ec22ca23af9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>