fn section_check(
    logs: &mut Logs,
    tags: &Tags,
    idx: SectionIdx,
    section: &ContentFilterSection,
    params: &RequestField,
    ignore_alphanum: bool,
    omit: &mut Omitted,
) -> Result<(), ContentFilterBlock> {
    if idx != SectionIdx::Path && params.len() > section.max_count {
        if section.max_count > 0 {
            return Err(ContentFilterBlock::TooManyEntries(idx));
        } else {
            logs.warning(|| format!("In section {:?}, param_count = 0", idx));
        }
    }

    for (name, value) in params.iter() {
        // skip decoded parameters for length checks
        if !name.ends_with(":decoded") && value.len() > section.max_length {
            if section.max_length > 0 {
                return Err(ContentFilterBlock::EntryTooLarge(idx, name.to_string()));
            } else {
                logs.warning(|| format!("In section {:?}, max_length = 0", idx));
            }
        }

        // automatically ignored
        if ignore_alphanum && value.chars().all(|c| c.is_ascii_alphanumeric()) {
            omit.entries.at(idx).insert(name.to_string());
            continue;
        }

        // logic for checking an entry
        let mut check_entry = |name_entry: &ContentFilterEntryMatch| {
            let matched = if let Some(re) = &name_entry.reg {
                re.matches(value)
            } else {
                false
            };
            if matched {
                omit.entries.at(idx).insert(name.to_string());
            } else if name_entry.restrict {
                return Err(ContentFilterBlock::Mismatch(ContentFilterMatched::new(
                    idx,
                    name.to_string(),
                    value.to_string(),
                )));
            } else if tags.has_intersection(&name_entry.exclusions) {
                omit.entries.at(idx).insert(name.to_string());
            } else if !name_entry.exclusions.is_empty() {
                let entry = omit.exclusions.at(idx).entry(name.to_string()).or_default();
                entry.extend(name_entry.exclusions.iter().cloned());
            }
            Ok(())
        };

        // check name rules
        if let Some(entry) = section.names.get(name) {
            check_entry(entry)?;
            // if an argument was matched by exact check, we do not try to match it against regex rules
            continue;
        }

        // // check regex rules
        for entry in section
            .regex
            .iter()
            .filter_map(|(re, v)| if re.is_match(name) { Some(v) } else { None })
        {
            check_entry(entry)?;
        }
    }

    Ok(())
}
/// checks a section (headers, args, cookies) against the policy
checks a section (headers, args, cookies) against the policy
checks a section ( headers args cookies ) against the policy
fn section_check(
    logs: &mut Logs,
    tags: &Tags,
    idx: SectionIdx,
    section: &ContentFilterSection,
    params: &RequestField,
    ignore_alphanum: bool,
    omit: &mut Omitted,
) -> Result<(), ContentFilterBlock> {
    if idx != SectionIdx::Path && params.len() > section.max_count {
        if section.max_count > 0 {
            return Err(ContentFilterBlock::TooManyEntries(idx));
        } else {
            logs.warning(|| format!("In section {:?}, param_count = 0", idx));
        }
    }
    for (name, value) in params.iter() {
        // skip decoded parameters for length checks
        if !name.ends_with(":decoded") && value.len() > section.max_length {
            if section.max_length > 0 {
                return Err(ContentFilterBlock::EntryTooLarge(idx, name.to_string()));
            } else {
                logs.warning(|| format!("In section {:?}, max_length = 0", idx));
            }
        }
        // automatically ignored
        if ignore_alphanum && value.chars().all(|c| c.is_ascii_alphanumeric()) {
            omit.entries.at(idx).insert(name.to_string());
            continue;
        }
        // logic for checking an entry
        let mut check_entry = |name_entry: &ContentFilterEntryMatch| {
            let matched = if let Some(re) = &name_entry.reg {
                re.matches(value)
            } else {
                false
            };
            if matched {
                omit.entries.at(idx).insert(name.to_string());
            } else if name_entry.restrict {
                return Err(ContentFilterBlock::Mismatch(ContentFilterMatched::new(
                    idx,
                    name.to_string(),
                    value.to_string(),
                )));
            } else if tags.has_intersection(&name_entry.exclusions) {
                omit.entries.at(idx).insert(name.to_string());
            } else if !name_entry.exclusions.is_empty() {
                let entry = omit.exclusions.at(idx).entry(name.to_string()).or_default();
                entry.extend(name_entry.exclusions.iter().cloned());
            }
            Ok(())
        };
        // check name rules
        if let Some(entry) = section.names.get(name) {
            check_entry(entry)?;
            // if an argument was matched by exact check, we do not try to match it against regex rules
            continue;
        }
        // // check regex rules
        for entry in section
            .regex
            .iter()
            .filter_map(|(re, v)| if re.is_match(name) { Some(v) } else { None })
        {
            check_entry(entry)?;
        }
    }
    Ok(())
}
fn section_check ( logs : & mut Logs , tags : & Tags , idx : SectionIdx , section : & ContentFilterSection , params : & RequestField , ignore_alphanum : bool , omit : & mut Omitted , ) -> Result < ( ) , ContentFilterBlock > { if idx != SectionIdx :: Path && params . len ( ) > section . max_count { if section . max_count > 0 { return Err ( ContentFilterBlock :: TooManyEntries ( idx ) ) ; } else { logs . warning ( | | format ! ( " " idx ) ) ; } } for ( name , value ) in params . iter ( ) { // skip decoded parameters for length checks if ! name . ends_with ( " " ) && value . len ( ) > section . max_length { if section . max_length > 0 { return Err ( ContentFilterBlock :: EntryTooLarge ( idx , name . to_string ( ) ) ) ; } else { logs . warning ( | | format ! ( " " idx ) ) ; } } // automatically ignored if ignore_alphanum && value . chars ( ) . all ( | c | c . is_ascii_alphanumeric ( ) ) { omit . entries . at ( idx ) . insert ( name . to_string ( ) ) ; continue ; } // logic for checking an entry let mut check_entry = | name_entry : & ContentFilterEntryMatch | { let matched = if let Some ( re ) = & name_entry . reg { re . matches ( value ) } else { false } ; if matched { omit . entries . at ( idx ) . insert ( name . to_string ( ) ) ; } else if name_entry . restrict { return Err ( ContentFilterBlock :: Mismatch ( ContentFilterMatched :: new ( idx , name . to_string ( ) , value . to_string ( ) , ) ) ) ; } else if tags . has_intersection ( & name_entry . exclusions ) { omit . entries . at ( idx ) . insert ( name . to_string ( ) ) ; } else if ! name_entry . exclusions . is_empty ( ) { let entry = omit . exclusions . at ( idx ) . entry ( name . to_string ( ) ) . or_default ( ) ; entry . extend ( name_entry . exclusions . iter ( ) . cloned ( ) ) ; } Ok ( ( ) ) } ; // check name rules if let Some ( entry ) = section . names . get ( name ) { check_entry ( entry ) ? ; // if an argument was matched by exact check, we do not try to match it against regex rules continue ; } // // check regex rules for entry in section . regex . iter ( ) . filter_map ( | ( re , v ) | if re . is_match ( name ) { Some ( v ) } else { None } ) { check_entry ( entry ) ? ; } } Ok ( ( ) ) }
checks a section (headers, args, cookies) against the policy
checks a section ( headers args cookies ) against the policy
logs
&mut Logs
tags
&Tags
idx
SectionIdx
section
&ContentFilterSection
params
&RequestField
ignore_alphanum
bool
omit
&mut Omitted