# User Armor: An Extension for AppArmor
## 6 Application: Hardening Answer Set Programming Solvers  
Answer Set Programming (ASP) is a declarative programming paradigm designed for solving complex combinatorial problems [22; 23; 24]. It is widely used in artificial intelligence, knowledge representation and automated reasoning [25; 26; 27; 28]. Without going into much details, ASP programs comprise logic rules and are associated with zero or more stable models, that is, first-order models satisfying an additional stability condition designed to interpret default negation. Figure 3: Execution time for running the Bash script in our benchmark under different security policies. **Example 5**. : _Let us consider the Hamiltonian Path problem:_  
_Given a directed graph_ \(G\)_, a starting node_ \(s\) _and a target node_ \(t\)_, we need to find a path from_ \(s\) _to_ \(t\) _that visits all nodes of_ \(G\) _exactly once._  
_The graph shown in Figure_ 4 _can be represented by the following ASP:_  
_start(\"A\"). target(\"G\")._ _mode(\"A\"). link(\"A\",\"B\"). link(\"A\",\"C\"). node(\"B\"). link(\"B\",\"A\"). link(\"B\",\"D\"). node(\"C\"). link(\"C\",\"A\"). link(\"C\",\"D\"). node(\"D\"). link(\"D\",\"B\"). link(\"D\",\"C\"). link(\"D\",\"E\"). node(\"E\"). link(\"E\",\"D\"). link(\"E\",\"E\"). link(\"E\",\"E\"). node(\"E\"). link(\"F\",\"G\"). node(\"H\"). link(\"H\",\"F\"). node(\"G\"). link(\"G\",\"F\"). link(\"G\",\"H\"). We couple the above facts with rules addressing the Hamiltonian Path problem as follows:_  
_reach(I) :- start(I). reach(I) :- next(I,Y)._  
_{next(I,Y) : link(I,Y)] = 1 :- reach(I), not target(I). :- next(I,Y), next(Z,Y), Y < Z. :- node(I), not reach(I)._  
_Notably, the first two rules above define the reached nodes (reach/1) from the starting node (start/1), following the selected links (next/2). The links are selected by the third rule, which is also called the choice rule; for every reached node not being the target node, exactly one of its outgoing link is selected. The last two rules above, which are also called constraints, ensure that no node has two selected incoming links and that every node is reached. Stable models of the above program represent the Hamiltonian Paths of the given graph; in this case, the unique stable model extends the input facts with the following facts:_  
_reach(\"A\"). reach(\"B\"). reach(\"C\"). reach(\"D\"). reach(\"E\"). reach(\"F\"). reach(\"H\"). reach(\"G\"). next(\"A\",\"B\"). next(\"B\",\"C\"). next(\"C\",\"D\"). next(\"D\",\"E\"). next(\"E\",\"H\"). next(\"F\",\"G\"). next(\"H\",\"F\")._  
_The example can be run in the browser using the following ASP Chef [29; 30] recipe: [[https://asp-chefalviano.net/s/hamiltonian-path@algorithm2025](https://asp-chefalviano.net/s/hamiltonian-path@algorithm2025)]([https://asp-chefalviano.net/s/hamiltonian-path@algorithm2025](https://asp-chefalviano.net/s/hamiltonian-path@algorithm2025)) (accessed on 26 February 2025). A graphical representation of the computed Hamiltonian Path is given in Figure_ 4_._  
The state-of-the-art solver clingo[12] is one of the most popular ASP solvers, offering a powerful inference engine that can be extended with Python v3.12 and Lua v5.4 scripts to enhance reasoning capabilities. Other frequently used ASP solvers are dlv[31], smodels[32], cmodels[33], idp[34] and wasp[35]. ASP can be used to develop web-based AI applications, and this is a common scenario for researchers aiming at showcasing their AI-powered tools that solve hard combinatorial tasks using ASP [36; 37; 38]. They provide a web app with a user-friendly interface (e.g., a textarea for input), where an ASP solver is executed in the backend server to process queries and return computed results. While this approach is functional, it introduces serious security vulnerabilities. CLINGO supports @-terms, which allow interpreted functions to be evaluated dynamically. These functions can be defined in either Lua or Python, meaning that CLINGO can execute arbitrary Python or Lua code.