Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

nginx: [emerg] "BasicRule" directive is not allowed here in whitelist rules #40

Open
vncloudsco opened this issue Oct 13, 2021 · 8 comments

Comments

@vncloudsco
Copy link
Contributor

i am trying to configure the following but am getting an error how can i fix it

Vhost myconfig:

    location / {
         include /etc/nginx/naxsi-rules/rules/block.rules;
........

block.rules file:

#Enable naxsi
   SecRulesEnabled;
   #Enable learning mode
   # LearningMode;
   #Define where blocked requests go
   DeniedUrl "/50x.html"; 
   #CheckRules, determining when naxsi needs to take action
   CheckRule "$SQL >= 8" BLOCK;
   CheckRule "$RFI >= 8" BLOCK;
   CheckRule "$TRAVERSAL >= 4" BLOCK;
   CheckRule "$EVADE >= 4" BLOCK;
   CheckRule "$XSS >= 8" BLOCK;
   LibInjectionXss;
   CheckRule "$LIBINJECTION_XSS >= 8" BLOCK;
   LibInjectionSql;
   CheckRule "$LIBINJECTION_SQL >= 8" BLOCK;
   CheckRule "$EVADE >= 4" BLOCK;
   CheckRule "$ATTACK >= 8" BLOCK;
   CheckRule "$UWA >= 8" BLOCK;
   #naxsi logs goes there
# include /etc/nginx/naxsi-rules/rules/whitelist.rules;

 if ($host = yyyyyy.com ) {
        include /etc/nginx/naxsi-rules/rules/yyyyyy.com.rules;
 }
 if ($host = xxxxxx.com ) {
        include /etc/nginx/naxsi-rules/rules/xxxxxx.com.rules;;
}

nginx check:

nginx: [emerg] "BasicRule" directive is not allowed here in /etc/nginx/naxsi-rules/rules/yyyyyy.com.rules:1
nginx: configuration file /etc/nginx/nginx.conf test failed

if I configure the block file like this, it works again

block.rules file:

#Enable naxsi
   SecRulesEnabled;
   #Enable learning mode
   # LearningMode;
   #Define where blocked requests go
   DeniedUrl "/50x.html"; 
   #CheckRules, determining when naxsi needs to take action
   CheckRule "$SQL >= 8" BLOCK;
   CheckRule "$RFI >= 8" BLOCK;
   CheckRule "$TRAVERSAL >= 4" BLOCK;
   CheckRule "$EVADE >= 4" BLOCK;
   CheckRule "$XSS >= 8" BLOCK;
   LibInjectionXss;
   CheckRule "$LIBINJECTION_XSS >= 8" BLOCK;
   LibInjectionSql;
   CheckRule "$LIBINJECTION_SQL >= 8" BLOCK;
   CheckRule "$EVADE >= 4" BLOCK;
   CheckRule "$ATTACK >= 8" BLOCK;
   CheckRule "$UWA >= 8" BLOCK;
   #naxsi logs goes there
include /etc/nginx/naxsi-rules/rules/yyyyyy.com.rules;

nginx check:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

how can i use if check host with nginx here?

@vncloudsco
Copy link
Contributor Author

vncloudsco commented Oct 13, 2021

I changed the configuration to the following:

location / {
     if ($host = xxxxxxxxxxxxxx ) {
         include /etc/nginx/naxis-rules/rules/block.rules;
    }

but i still get the error

nginx: [emerg] "BasicRule" directive is not allowed here in /etc/nginx/naxis-rules/rules/block.rules:1
nginx: configuration file /etc/nginx/nginx.conf test failed

We see this as a bug @wargio you can check. problem software did not read nginx configuration

@wargio
Copy link
Contributor

wargio commented Oct 13, 2021

Rules are not supported within an if block. if you have multiple hosts, etc.. i suggest to have a different http configuration

@vncloudsco
Copy link
Contributor Author

@wargio How do configure it? I have to include files one by one in each vhost? this is a really bad idea.

@wargio
Copy link
Contributor

wargio commented Oct 13, 2021

there is a PR for that actually.

@wargio
Copy link
Contributor

wargio commented Oct 13, 2021

nbs-system/naxsi#562

@vncloudsco
Copy link
Contributor Author

@wargio i have some questions.

  • why is the if block not supported and will it be supported in the future?
  • I have read the PR you sent but I still don't understand how to configure it?

@wargio
Copy link
Contributor

wargio commented Oct 14, 2021

that PR actually allows to setup naxsi at config and server level, this means that you need to include the naxsi configuration only once. i can't answer to the when and why because i do not know the reasons.

@vncloudsco
Copy link
Contributor Author

that PR actually allows to setup naxsi at config and server level

what does this mean? actually I don't understand how configuring it will be, because there is not description there is no documentation about the configuration?

this means that you need to include the naxsi configuration only once

means now we just need to include the file in nginx.conf? but i want to manage vhost in a simpler way through if block or $host in nginx,

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants