xss.h
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
// See accompanying file COPYING.TXT file for licensing details.
//
#ifndef CPPCMS_XSS_H
#define CPPCMS_XSS_H
#include <booster/copy_ptr.h>
#include <booster/regex.h>
#include <booster/function.h>
#include <cppcms/defs.h>
#include <string.h>
#include <string>
#include <algorithm>
namespace cppcms {
namespace json {
class value;
}
namespace xss {
namespace details {
class c_string;
}
struct basic_rules_holder;
class CPPCMS_API rules {
public:
rules();
rules(rules const &);
rules const &operator=(rules const &);
~rules();
rules(json::value const &r);
rules(std::string const &file_name);
typedef enum {
xhtml_input,
html_input
} html_type;
typedef enum {
invalid_tag = 0,
opening_and_closing = 1,
stand_alone = 2,
any_tag = 3,
} tag_type;
html_type html() const;
void html(html_type t);
void add_tag(std::string const &name,tag_type = any_tag);
void add_entity(std::string const &name);
bool numeric_entities_allowed() const;
void numeric_entities_allowed(bool v);
typedef booster::function<bool(char const *begin,char const *end)> validator_type;
void add_boolean_property(std::string const &tag_name,std::string const &property);
void add_property(std::string const &tag_name,std::string const &property,validator_type const &val);
void add_property(std::string const &tag_name,std::string const &property,booster::regex const &r);
void add_integer_property(std::string const &tag_name,std::string const &property);
void add_uri_property(std::string const &tag_name,std::string const &property);
void add_uri_property(std::string const &tag_name,std::string const &property,std::string const &schema);
CPPCMS_DEPRECATED static booster::regex uri_matcher();
CPPCMS_DEPRECATED static booster::regex uri_matcher(std::string const &schema);
static validator_type uri_validator();
static validator_type uri_validator(std::string const &scheme,bool absolute_only = false);
static validator_type relative_uri_validator();
bool comments_allowed() const;
void comments_allowed(bool comments);
void encoding(std::string const &enc);
tag_type valid_tag(details::c_string const &tag) const;
bool valid_boolean_property(details::c_string const &tag,details::c_string const &property) const;
bool valid_property(details::c_string const &tag,details::c_string const &property,details::c_string const &value) const;
bool valid_entity(details::c_string const &val) const;
std::string encoding() const;
private:
basic_rules_holder &impl();
basic_rules_holder const &impl() const;
struct data;
booster::copy_ptr<data> d;
};
typedef enum {
remove_invalid,
escape_invalid
} filtering_method_type;
CPPCMS_API bool validate(char const *begin,char const *end,rules const &r);
CPPCMS_API bool validate_and_filter_if_invalid( char const *begin,
char const *end,
rules const &r,
std::string &filtered,
filtering_method_type method=remove_invalid,
char replacement_char = 0);
CPPCMS_API std::string filter(char const *begin,
char const *end,
rules const &r,
filtering_method_type method=remove_invalid,
char replacement_char = 0);
CPPCMS_API std::string filter(std::string const &input,
rules const &r,
filtering_method_type method=remove_invalid,
char replacement_char = 0);
} // xss
}
#endif
booster::regex
This is a simple wrapper of PCRE library.
Definition: perl_regex.h:35
cppcms::json::value
This class is central representation of json objects.
Definition: json.h:142
cppcms::xss::filter
CPPCMS_API std::string filter(char const *begin, char const *end, rules const &r, filtering_method_type method=remove_invalid, char replacement_char=0)
Filter the input in range [begin, end) according to the rules r using filtering method method...
cppcms::xss::rules::tag_type
tag_type
Definition: xss.h:201
cppcms::xss::validate
CPPCMS_API bool validate(char const *begin, char const *end, rules const &r)
Check the input in range [begin, end) according to the rules r.
booster::copy_ptr< data >
cppcms::xss::rules
The class that holds XSS filter rules.
Definition: xss.h:90
cppcms::xss::rules::validator_type
booster::function< bool(char const *begin, char const *end)> validator_type
Definition: xss.h:245
cppcms::xss::filtering_method_type
filtering_method_type
The enumerator that defines filtering invalid HTML method.
Definition: xss.h:414
booster::function
Definition: function.h:16
cppcms::xss::validate_and_filter_if_invalid
CPPCMS_API bool validate_and_filter_if_invalid(char const *begin, char const *end, rules const &r, std::string &filtered, filtering_method_type method=remove_invalid, char replacement_char=0)
Validate the input in range [begin, end) according to the rules r and if it is not valid filter it an...
cppcms::xss::rules::xhtml_input
Assume that the input is XHTML.
Definition: xss.h:194
cppcms::xss::remove_invalid
Remove all invalid HTML form the input.
Definition: xss.h:415
cppcms::xss::escape_invalid
Escape (convert to text) all invalid HTML in the input.
Definition: xss.h:416