Skip to content

[request help] can you give a example for pure http server using libmodsecurity #3324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xx-zhang opened this issue Jan 9, 2025 · 1 comment

Comments

@xx-zhang
Copy link

xx-zhang commented Jan 9, 2025

what i want to do is using mosecurity for rule check, and i don't want to use nginx-modsecurity-connector or apache, so i want to make a http server this use modsecruity direct, for example, we can use httplib_cpp + modsecurity make a pure server , how can i do it.

#define CPPHTTPLIB_OPENSSL_SUPPORT
#include "path/to/httplib.h"

#include "path/to/modsecurity.h"

using ModSecurity::ModSecurity;
using ModSecurity::Rules;
using ModSecurity::Transaction;

bool do_modsecurity_parse_and_inject( ... ){
    ModSecurity *modsec;
    ModSecurity::Rules *rules;
    
    modsec = new ModSecurity();
    
    rules = new Rules();
    rules->loadFromUri(rules_file);
    Transaction *modsecTransaction = new Transaction(modsec, rules);
  
    // modsecTransaction->processConnection("127.0.0.1");

}

if (modsecTransaction->intervention()) {
   std::cout << "There is an intervention" << std::endl;
}

// HTTP
httplib::Server svr;

// HTTPS
httplib::SSLServer svr;

svr.Get("/hi", [](const httplib::Request &, httplib::Response &res) {
  res.set_content("Hello World!", "text/plain");
   // what i want to get the using way. 
  auto is_inject = do_modsecurity_parse_and_inject( ... ); 

});

svr.listen("0.0.0.0", 8080);
@xx-zhang
Copy link
Author

xx-zhang commented Jan 9, 2025

i have see the example transaction and have get some idea.

@xx-zhang xx-zhang closed this as completed Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant