Runtime Application Self-Protection (RASP): What it is and how to implement it

  


Application security is increasingly critical: companies can no longer rely solely on firewalls, WAFs, or network controls. Modern attacks exploit vulnerabilities at the application level, often while it is running. This is where Runtime Application Self-Protection (RASP) comes into play: a technology that integrates directly into the application and protects it "from the inside," monitoring and blocking malicious behavior in real time.

🔗 Do you like Techelopment? Check out the site for all the details!

What is RASP

RASP is a defense mechanism integrated into the application runtime.

  • It is not an "external" product, like a WAF, but runs within the application process itself.
  • It intercepts sensitive calls and actions (database queries, command executions, system library calls, user input/output).
  • It analyzes the context to understand whether an operation is legitimate or potentially malicious (e.g., SQL injection, RCE, path traversal).
  • It can block the attack, alert the logs and in some cases even auto-correct the execution.

In essence, RASP combines application monitoring + intrusion prevention at the code level.


How it works technically

Here are the main approaches:

  1. Instrumentation: the app code is "instrumented" (with agents or libraries) to intercept critical functions.
  2. Runtime hooking: RASP hooks into language calls (e.g., JDBC methods in Java, parsing functions in .NET, command executions in Node.js).
  3. Behavioral analysis: combines known signatures with behavioral models (e.g., "this query is not typical” → block).

Example: SQL Injection Protection

Let's imagine a Java application that executes SQL queries:

Senzo RASP

String query = "SELECT * FROM users WHERE username = '" + userInput + "'";
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(query);

An attacker could insert:

' OR '1'='1

and bypass authentication.

With RASP (simplified logic)

RASP intercepts the query before execution:

  • Parses the SQL string.
  • Detects suspicious patterns (' OR '1'='1).
  • Blocks execution or rewrites the query.

RASP agent pseudocode:

public ResultSet safeExecuteQuery(String query) throws SecurityException {
  if (isMalicious(query)) {
    logAttack("SQL Injection attempt: " + query);
    throw new SecurityException("Blocked malicious SQL");
  }
  return realStatement.executeQuery(query);
}

private boolean isMalicious(String query) {
  // Detects tautologies or known manipulations
  return query.toLowerCase().contains(" or '1'='1")
  || query.toLowerCase().matches(".*(--|;).*");
}

Practical Implementation

Companies don't write a RASP from scratch; they use ready-made solutions, often agents that can be integrated into the runtime. Some examples:

  • Contrast Security
  • Imperva RASP
  • Micro Focus Fortify
  • Sqreen (now Datadog Application Security)

Typical Integration Steps

  1. Install the agent: a jar/agent (Java), a .NET library, or a middleware for Node.js.
  2. Configure policies: what to log, what to block.
  3. Testing in staging: observe false positives and adjust.
  4. Deployment in production: the RASP runs "inside" the app, without requiring code changes in most cases.

Practical example: integrating the Contrast Security Java agent into a Spring Boot app

1. Prerequisites

- Spring Boot app (executable jar).
- Contrast account (or Community Edition) to download the agent and obtain credentials.
(Contrast provides a “drop-in” agent that instruments the JVM and collects runtime data.)

2. Download the agent

From the Contrast console, download the contrast.jar (or contrast-agent.jar) file or obtain it via Maven as indicated in the doc.

3. Launch the app with the agent

Example: Your app is app.jar, the agent jar is /opt/contrast/contrast.jar:

java -javaagent:/opt/contrast/contrast.jar -jar app.jar

Or, if you want to pass configuration parameters (e.g., Contrast server URL, token), follow the instructions in the Contrast console — they often set environment variables or JVM arguments.

4. Initial configuration

  • In the Contrast interface, add the app (Add Agent) and download/obtain credentials.
  • The agent automatically starts monitoring requests, sensitive data flows, and vulnerabilities at runtime; You can enable blocking or monitoring-only mode during testing.

5. Practical Test (SQLi)

Suppose a vulnerable endpoint /login that accepts username and password. Manually test with curl:

curl -X POST http://localhost:8080/login \
-d "username=admin' OR '1'='1&password=whatever"

What happens when the agent is active:

  • The agent detects suspicious patterns/data flows that match SQLi.
  • In block mode, access is blocked; In monitor mode, evidence of the attack is logged in the Contrast console.

6. Practical tips + best practices

  • Staging testing: Always put RASP in monitoring before enabling blocking to reduce false positives. Gradual onboarding is the rule.
  • Metrics and overhead: Measure CPU/latency because instrumentation introduces overhead; size nodes if necessary.
  • Logging & Alerting: Integrate RASP outputs into your SIEM/monitoring for quick responses.
  • DevSecOps: Use RASP results to fix code (not just as bandwidth containment).

Practical tip: When deploying a RASP agent into production, first enable 'monitor' mode and collect signals for at least a few days/a week (depending on traffic) to fine-tune the rules and minimize false positives. Only then can you switch to selective blocking policies for well-known attack classes (e.g., SQLi, RCE).


Advantages and Limitations

Advantages

  • Immediate protection against zero-day exploits.
  • Richer application context than a WAF.
  • Relatively simple deployment (no infrastructure changes required).

⚠️ Limitations

  • Possible performance overhead.
  • Risk of false positives.
  • Not a substitute for secure development (DevSecOps).

Conclusion

The Runtime Application Self-Protection isn't a magic wand, but it represents a fundamental element of defense-in-depth. By integrating RASP, an application isn't simply "subjected" to external controls, but acquires the ability to defend itself autonomously during execution.



Follow me #techelopment

Official site: www.techelopment.it
facebook: Techelopment
instagram: @techelopment
X: techelopment
Bluesky: @techelopment
telegram: @techelopment_channel
whatsapp: Techelopment
youtube: @techelopment