|
17 | 17 | #include"modsecurity.h" |
18 | 18 | #include"msc_logging.h" |
19 | 19 | #include"msc_util.h" |
| 20 | +#include"pdf_protect.h" |
20 | 21 | #include"http_log.h" |
21 | 22 | #include"apr_lib.h" |
22 | 23 | #include"acmp.h" |
@@ -112,6 +113,14 @@ void *create_directory_config(apr_pool_t *mp, char *path) |
112 | 113 | dcfg->stream_inbody_inspection=NOT_SET; |
113 | 114 | dcfg->stream_outbody_inspection=NOT_SET; |
114 | 115 |
|
| 116 | +/* PDF XSS protection. */ |
| 117 | +dcfg->pdfp_enabled=NOT_SET; |
| 118 | +dcfg->pdfp_secret=NOT_SET_P; |
| 119 | +dcfg->pdfp_timeout=NOT_SET; |
| 120 | +dcfg->pdfp_token_name=NOT_SET_P; |
| 121 | +dcfg->pdfp_only_get=NOT_SET; |
| 122 | +dcfg->pdfp_method=NOT_SET; |
| 123 | + |
115 | 124 | /* Geo Lookups */ |
116 | 125 | dcfg->geo=NOT_SET_P; |
117 | 126 |
|
@@ -523,6 +532,20 @@ void *merge_directory_configs(apr_pool_t *mp, void *_parent, void *_child) |
523 | 532 | merged->stream_outbody_inspection= (child->stream_outbody_inspection==NOT_SET |
524 | 533 | ?parent->stream_outbody_inspection :child->stream_outbody_inspection); |
525 | 534 |
|
| 535 | +/* PDF XSS protection. */ |
| 536 | +merged->pdfp_enabled= (child->pdfp_enabled==NOT_SET |
| 537 | + ?parent->pdfp_enabled :child->pdfp_enabled); |
| 538 | +merged->pdfp_secret= (child->pdfp_secret==NOT_SET_P |
| 539 | + ?parent->pdfp_secret :child->pdfp_secret); |
| 540 | +merged->pdfp_timeout= (child->pdfp_timeout==NOT_SET |
| 541 | + ?parent->pdfp_timeout :child->pdfp_timeout); |
| 542 | +merged->pdfp_token_name= (child->pdfp_token_name==NOT_SET_P |
| 543 | + ?parent->pdfp_token_name :child->pdfp_token_name); |
| 544 | +merged->pdfp_only_get= (child->pdfp_only_get==NOT_SET |
| 545 | + ?parent->pdfp_only_get :child->pdfp_only_get); |
| 546 | +merged->pdfp_method= (child->pdfp_method==NOT_SET |
| 547 | + ?parent->pdfp_method :child->pdfp_method); |
| 548 | + |
526 | 549 | /* Geo Lookup */ |
527 | 550 | merged->geo= (child->geo==NOT_SET_P |
528 | 551 | ?parent->geo :child->geo); |
@@ -678,6 +701,14 @@ void init_directory_config(directory_config *dcfg) |
678 | 701 | if (dcfg->stream_inbody_inspection==NOT_SET)dcfg->stream_inbody_inspection=0; |
679 | 702 | if (dcfg->stream_outbody_inspection==NOT_SET)dcfg->stream_outbody_inspection=0; |
680 | 703 |
|
| 704 | +/* PDF XSS protection. */ |
| 705 | +if (dcfg->pdfp_enabled==NOT_SET)dcfg->pdfp_enabled=0; |
| 706 | +if (dcfg->pdfp_secret==NOT_SET_P)dcfg->pdfp_secret=NULL; |
| 707 | +if (dcfg->pdfp_timeout==NOT_SET)dcfg->pdfp_timeout=10; |
| 708 | +if (dcfg->pdfp_token_name==NOT_SET_P)dcfg->pdfp_token_name="PDFPTOKEN"; |
| 709 | +if (dcfg->pdfp_only_get==NOT_SET)dcfg->pdfp_only_get=1; |
| 710 | +if (dcfg->pdfp_method==NOT_SET)dcfg->pdfp_method=PDF_PROTECT_METHOD_TOKEN_REDIRECTION; |
| 711 | + |
681 | 712 | /* Geo Lookup */ |
682 | 713 | if (dcfg->geo==NOT_SET_P)dcfg->geo=NULL; |
683 | 714 |
|
@@ -2812,7 +2843,6 @@ static const char *cmd_cache_transformations(cmd_parms *cmd, void *_dcfg, |
2812 | 2843 | if (intval<0) { |
2813 | 2844 | returnapr_psprintf(cmd->pool,"ModSecurity: SecCacheTransformations maxlen must be positive: %s",charval); |
2814 | 2845 | } |
2815 | | - |
2816 | 2846 | /* The NOT_SET indicator is -1, a signed long, and therfore |
2817 | 2847 | * we cannot be >= the unsigned value of NOT_SET. |
2818 | 2848 | */ |
@@ -2844,6 +2874,26 @@ static const char *cmd_cache_transformations(cmd_parms *cmd, void *_dcfg, |
2844 | 2874 | } |
2845 | 2875 |
|
2846 | 2876 |
|
| 2877 | +staticconstchar*cmd_pdf_protect_method(cmd_parms*cmd,void*_dcfg, |
| 2878 | +constchar*p1) |
| 2879 | +{ |
| 2880 | +directory_config*dcfg= (directory_config*)_dcfg; |
| 2881 | +if (dcfg==NULL)returnNULL; |
| 2882 | + |
| 2883 | +if (strcasecmp(p1,"TokenRedirection")==0) { |
| 2884 | +dcfg->pdfp_method=PDF_PROTECT_METHOD_TOKEN_REDIRECTION; |
| 2885 | + }else |
| 2886 | +if (strcasecmp(p1,"ForcedDownload")==0) { |
| 2887 | +dcfg->pdfp_method=PDF_PROTECT_METHOD_FORCED_DOWNLOAD; |
| 2888 | + }else { |
| 2889 | +return (constchar*)apr_psprintf(cmd->pool, |
| 2890 | +"ModSecurity: Unrecognised parameter value for SecPdfProtectMethod: %s",p1); |
| 2891 | + } |
| 2892 | + |
| 2893 | +returnNULL; |
| 2894 | +} |
| 2895 | + |
| 2896 | + |
2847 | 2897 | /* -- Configuration directives definitions -- */ |
2848 | 2898 |
|
2849 | 2899 | #defineCMD_SCOPE_MAIN (RSRC_CONF) |
@@ -3520,6 +3570,14 @@ const command_rec module_directives[] = { |
3520 | 3570 | "Set Hash key" |
3521 | 3571 | ), |
3522 | 3572 |
|
| 3573 | +AP_INIT_TAKE1 ( |
| 3574 | +"SecPdfProtectMethod", |
| 3575 | +cmd_pdf_protect_method, |
| 3576 | +NULL, |
| 3577 | +RSRC_CONF, |
| 3578 | +"protection method to use. Can be 'TokenRedirection' (default) or 'ForcedDownload'" |
| 3579 | + ), |
| 3580 | + |
3523 | 3581 | AP_INIT_TAKE1 ( |
3524 | 3582 | "SecHashParam", |
3525 | 3583 | cmd_hash_param, |
|