Rspamd symbols

Vsevolod Stakhov
Vsevolod StakhovSoftware Engineer at Mimecast
SYMBOLS AND RULES
RSPAMD
WHAT ARE SYMBOLS AND RULES
DEFINITIONS
RULE SYMBOL
SCORE
GROUP
DESCRIPTION
WEIGHT
*
true/false
OPTIONS
Dynamic part
Static part
∑ Results
FLAGS
WHAT ARE SYMBOLS AND RULES
WHY DO WE NEED SYMBOLS
RULE
SYMBOL_ALLOW
SYMBOL_DENY
SYMBOL_UNKNOWN
Either of symbols
WHAT ARE SYMBOLS AND RULES
WHY DO WE NEED SYMBOLS
RULE
MAP1
MAP2
MAP3
Multiple symbols
WHAT ARE SYMBOLS AND RULES
WHY DO WE NEED SYMBOLS
RULE1 SYMBOL1
RULE2
Dependency
WHAT ARE SYMBOLS AND RULES
RULES
▸ Rules define what is executed:
▸ Regexps expression
▸ Lua code
▸ Plugin logic
▸ Each rule can be associated with one or many symbols
▸ Rule can depend on other rules identified by associated symbols
▸ Each rule can define the current dynamic weight (usually from 0 to 1)
WHAT ARE SYMBOLS AND RULES
SYMBOLS
▸ Symbols define meta-information of a rule:
▸ Name
▸ Static score
▸ Other data (description, group, flags, etc)
▸ Symbols can be:
▸ Normal: associated with exactly one rule
▸ Virtual: are not associated with rules but grouped with normal symbol)
▸ Callback: do not have name or score, just define common rule
▸ Special: have special purpose (e.g. composite symbols)
SYMBOLS
SYMBOLS GROUPS
SYMBOL1
SYMBOL2
SYMBOL3
SYMBOL4
Group1
SYMBOL3
SYMBOL4
SYMBOL5
SYMBOL6
Group2
GROUP LIMIT
GROUP DESCRIPTION
SYMBOLS
SYMBOLS GROUPS
▸ Groups join common symbols logically
▸ Groups can set joint limit for symbols scores enclosed
▸ Groups can be used in composite rules:
▸ SYMBOL5 && G:GROUP1
▸ SYMBOL5 && (G:GROUP1 || !G:GROUP2)
RULES
EXPRESSIONS IN RULES
▸ Expressions are used in:
▸ Regexp rules
▸ Composite symbols
▸ Expressions have common syntax:
▸ Logic operations: AND (&&), OR (||), NOT (!)
▸ Braces
▸ Limit operation: A + B + C > 2
▸ Elements are called atoms
RULES
REGEXP EXPRESSIONS
▸ Atoms are regular expressions (/re/flags):
▸ Header: Header=/re/H
▸ Mime (/P): scan text parts
▸ Body (/B): scan full undecoded body
▸ URL (/U): scan URLs found
▸ There is no order of regexps execution within an expression
▸ Same expressions are cached and executed once
COMPOSITE EXPRESSIONS
COMPOSITES STRUCTURE
SYMBOL3
SYMBOL4
SYMBOL5
SYMBOL1
Group2
NOT SYMBOL6
AND
SYMBOL1 AND GR:GROUP2 AND !SYMBOL6
AND
COMPOSITE EXPRESSIONS
COMPOSITES OPERATIONS
SYMBOL3
SYMBOL4
SYMBOL5
SYMBOL1
Group2
NOT SYMBOL6
AND AND
SYMBOL1
SYMBOL3
Symbols to remove
Stage 1: Check
Stage 2: Remove symbols
COMPOSITE EXPRESSIONS
COMPOSITES STRUCTURE
▸ Composite atoms can include:
▸ Other symbols
▸ Groups (gr:)
▸ Other composites (with recursive references check)
▸ Composite operations can be the following:
▸ Remove symbol and weight (SYMBOL)
▸ Remove weight only (~SYMBOL)
▸ Remove symbol but preserve weight (-SYMBOL)
▸ Always remove symbol and weight (^SYMBOL)
COMPOSITE EXPRESSIONS
COMPOSITES OPERATION
▸ If any composite proposes that a symbol should NOT be
removed, then it is NOT removed:
▸ A & ~B and C & B: B will NOT be removed because of the
first rule, but its weight will be removed
▸ A & -B and C & ~B: neither weight, nor symbol B will be
removed
▸ Removal could be forced by “^” symbol:
▸ A & ^B and C & -B: weight and symbol B are both removed
PRACTICAL EXAMPLES
A SIMPLE REGEXP EXPRESSION
local reconf = config['regexp'] -- Define alias for regexp module
-- Define a single regexp rule
reconf['PRECEDENCE_BULK'] = {
-- Header regexp that detects bulk email
re = 'Precedence=/bulk/Hi',
-- Default score
score = 0.1,
description = "Message marked as bulk",
group = 'upstream_spam_filters'
}
rspamd.local.lua:
PRACTICAL EXAMPLES
A MORE COMPLEX EXAMPLE
rspamd.local.lua:
local reconf = config['regexp'] -- Define alias for regexp module
-- Define encodings types
-- /X is undecoded header
local subject_encoded_b64 = 'Subject=/=?S+?B?/iX'
local subject_encoded_qp = 'Subject=/=?S+?Q?/iX'
-- Define whether subject must be encoded (contains non-7bit characters)
local subject_needs_mime = 'Subject=/[x00-x08x0bx0cx0e-x1fx7f-xff]/X'
-- Final rule
reconf['SUBJECT_NEEDS_ENCODING'] = {
-- Combine regexps
re = string.format('!(%s) & !(%s) & (%s)', subject_encoded_b64,
subject_encoded_qp, subject_needs_mime),
score = 3.5,
description = "Subject contains non-ASCII chars but it is not encoded",
group = 'headers'
}
PRACTICAL EXAMPLES
A MORE COMPLEX EXAMPLE
rspamd.local.lua:
local reconf = config['regexp'] -- Define alias for regexp module
-- Define encodings types
-- /X is undecoded header
local subject_encoded_b64 = 'Subject=/=?S+?B?/iX'
local subject_encoded_qp = 'Subject=/=?S+?Q?/iX'
-- Define whether subject must be encoded (contains non-7bit characters)
local subject_needs_mime = 'Subject=/[x00-x08x0bx0cx0e-x1fx7f-xff]/X'
-- Final rule
reconf['SUBJECT_NEEDS_ENCODING'] = {
-- Combine regexps
re = string.format('!(%s) & !(%s) & (%s)', subject_encoded_b64,
subject_encoded_qp, subject_needs_mime),
score = 3.5,
description = "Subject contains non-ASCII chars but it is not encoded",
group = 'headers'
}
PRACTICAL EXAMPLES
A MORE COMPLEX EXAMPLE
rspamd.local.lua:
local reconf = config['regexp'] -- Define alias for regexp module
-- Define encodings types
-- /X is undecoded header
local subject_encoded_b64 = 'Subject=/=?S+?B?/iX'
local subject_encoded_qp = 'Subject=/=?S+?Q?/iX'
-- Define whether subject must be encoded (contains non-7bit characters)
local subject_needs_mime = 'Subject=/[x00-x08x0bx0cx0e-x1fx7f-xff]/X'
-- Final rule
reconf['SUBJECT_NEEDS_ENCODING'] = {
-- Combine regexps
re = string.format('!(%s) & !(%s) & (%s)', subject_encoded_b64,
subject_encoded_qp, subject_needs_mime),
score = 3.5,
description = "Subject contains non-ASCII chars but it is not encoded",
group = 'headers'
}
PRACTICAL EXAMPLES
COMPOSITES EXAMPLE
local.d/composites.conf:
# Ignore forged recipients in case of mailing list
composite "FORGED_RECIPIENTS_MAILLIST" {
# MALLIST symbol is preserved
expression = "FORGED_RECIPIENTS & -MAILLIST";
}
# Ignore forged sender if a message has been forwarded
composite "FORGED_SENDER_FORWARDING" {
# Symbols from `forwarding` group are removed
expression = "FORGED_SENDER & g:forwarding";
}
# Ignore forged sender if a message has been from the mailing list
composite "FORGED_SENDER_MAILLIST" {
# Symbol 'FORGED_SENDER' is forced to be removed
expression = "^FORGED_SENDER & -MAILLIST";
}
PRACTICAL EXAMPLES
COMPOSITES EXAMPLE
local.d/composites.conf:
# Ignore forged recipients in case of mailing list
composite "FORGED_RECIPIENTS_MAILLIST" {
# MALLIST symbol is preserved
expression = "FORGED_RECIPIENTS & -MAILLIST";
}
# Ignore forged sender if a message has been forwarded
composite "FORGED_SENDER_FORWARDING" {
# Symbols from `forwarding` group are removed
expression = "FORGED_SENDER & g:forwarding";
}
# Ignore forged sender if a message has been from the mailing list
composite "FORGED_SENDER_MAILLIST" {
# Symbol 'FORGED_SENDER' is forced to be removed
expression = "^FORGED_SENDER & -MAILLIST";
}
PRACTICAL EXAMPLES
COMPOSITES EXAMPLE
local.d/composites.conf:
# Ignore forged recipients in case of mailing list
composite "FORGED_RECIPIENTS_MAILLIST" {
# MALLIST symbol is preserved
expression = "FORGED_RECIPIENTS & -MAILLIST";
}
# Ignore forged sender if a message has been forwarded
composite "FORGED_SENDER_FORWARDING" {
# Symbols from `forwarding` group are removed
expression = "FORGED_SENDER & g:forwarding";
}
# Ignore forged sender if a message has been from the mailing list
composite "FORGED_SENDER_MAILLIST" {
# Symbol 'FORGED_SENDER' is forced to be removed
expression = "^FORGED_SENDER & -MAILLIST";
}
PRACTICAL EXAMPLES
COMPOSITES EXAMPLE
local.d/composites.conf:
# Ignore forged recipients in case of mailing list
composite "FORGED_RECIPIENTS_MAILLIST" {
# MALLIST symbol is preserved
expression = "FORGED_RECIPIENTS & -MAILLIST";
}
# Ignore forged sender if a message has been forwarded
composite "FORGED_SENDER_FORWARDING" {
# Symbols from `forwarding` group are removed
expression = "FORGED_SENDER & g:forwarding";
}
# Ignore forged sender if a message has been from the mailing list
composite "FORGED_SENDER_MAILLIST" {
# Symbol 'FORGED_SENDER' is forced to be removed
expression = "^FORGED_SENDER & -MAILLIST";
}
PRACTICAL EXAMPLES
COMPOSITES EXAMPLE
local.d/composites.conf:
# Ignore forged recipients in case of mailing list
composite "FORGED_RECIPIENTS_MAILLIST" {
# MALLIST symbol is preserved
expression = "FORGED_RECIPIENTS & -MAILLIST";
}
# Ignore forged sender if a message has been forwarded
composite "FORGED_SENDER_FORWARDING" {
# Symbols from `forwarding` group are removed
expression = "FORGED_SENDER & g:forwarding";
}
# Ignore forged sender if a message has been from the mailing list
composite "FORGED_SENDER_MAILLIST" {
# Symbol 'FORGED_SENDER' is forced to be removed
expression = "^FORGED_SENDER & -MAILLIST";
}
1 of 24

Recommended

Packages - PL/SQL by
Packages - PL/SQLPackages - PL/SQL
Packages - PL/SQLEsmita Gupta
403 views19 slides
Procedure and Functions in pl/sql by
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sqlÑirmal Tatiwal
6.5K views27 slides
Scalar expressions and control structures in perl by
Scalar expressions and control structures in perlScalar expressions and control structures in perl
Scalar expressions and control structures in perlsana mateen
2.9K views9 slides
Oracle - Program with PL/SQL - Lession 03 by
Oracle - Program with PL/SQL - Lession 03Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03Thuan Nguyen
2.4K views24 slides
Sql Objects And PL/SQL by
Sql Objects And PL/SQLSql Objects And PL/SQL
Sql Objects And PL/SQLGary Myers
1.2K views32 slides
Oracle - Program with PL/SQL - Lession 12 by
Oracle - Program with PL/SQL - Lession 12Oracle - Program with PL/SQL - Lession 12
Oracle - Program with PL/SQL - Lession 12Thuan Nguyen
2.5K views27 slides

More Related Content

What's hot

Cursors by
CursorsCursors
CursorsPriyanka Yadav
6.3K views38 slides
Integrity and security by
Integrity and securityIntegrity and security
Integrity and securitySurendra Karki Chettri
754 views18 slides
Functions oracle (pl/sql) by
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)harman kaur
3.9K views8 slides
Oracle: PLSQL Introduction by
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL IntroductionDataminingTools Inc
3.3K views9 slides
Hadoop Pig by
Hadoop PigHadoop Pig
Hadoop PigMathias Herberts
4K views52 slides
PLSQL Tutorial by
PLSQL TutorialPLSQL Tutorial
PLSQL TutorialQuang Minh Đoàn
2.4K views48 slides

What's hot(19)

Functions oracle (pl/sql) by harman kaur
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)
harman kaur3.9K views
COMPILER DESIGN by RRamyaDevi
COMPILER DESIGN COMPILER DESIGN
COMPILER DESIGN
RRamyaDevi199 views
Basic cursors in oracle by Suhel Firdus
Basic cursors in oracleBasic cursors in oracle
Basic cursors in oracle
Suhel Firdus1.2K views
The Story About The Migration by EDB
 The Story About The Migration The Story About The Migration
The Story About The Migration
EDB128 views
Oracle Baisc Tutorial by bunny0143
Oracle Baisc TutorialOracle Baisc Tutorial
Oracle Baisc Tutorial
bunny0143629 views
ORACLE PL SQL FOR BEGINNERS by mohdoracle
ORACLE PL SQL FOR BEGINNERSORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERS
mohdoracle18.6K views
Log4j by vasu12
Log4jLog4j
Log4j
vasu12677 views
Trigger and cursor program using sql by Sushil Mishra
Trigger and cursor program using sqlTrigger and cursor program using sql
Trigger and cursor program using sql
Sushil Mishra7.1K views
Perl names values and variables by sana mateen
Perl names values and variablesPerl names values and variables
Perl names values and variables
sana mateen2.6K views

Viewers also liked

Pkg slides from BSDCan conference by
Pkg slides from BSDCan conferencePkg slides from BSDCan conference
Pkg slides from BSDCan conferenceVsevolod Stakhov
929 views36 slides
Rspamd testing by
Rspamd testingRspamd testing
Rspamd testingVsevolod Stakhov
1.4K views16 slides
ast-rspamd by
ast-rspamdast-rspamd
ast-rspamdVsevolod Stakhov
1.1K views19 slides
New solver for FreeBSD pkg by
New solver for FreeBSD pkgNew solver for FreeBSD pkg
New solver for FreeBSD pkgVsevolod Stakhov
2.6K views31 slides
rspamd-hyperscan by
rspamd-hyperscanrspamd-hyperscan
rspamd-hyperscanVsevolod Stakhov
2.1K views15 slides
Cryptography and secure systems by
Cryptography and secure systemsCryptography and secure systems
Cryptography and secure systemsVsevolod Stakhov
1.3K views41 slides

Similar to Rspamd symbols

Hacking parse.y (RubyKansai38) by
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)ujihisa
1.1K views52 slides
Array and functions by
Array and functionsArray and functions
Array and functionsSun Technlogies
291 views23 slides
Hacking Parse.y with ujihisa by
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisaujihisa
854 views54 slides
11 ruby methods by
11 ruby methods11 ruby methods
11 ruby methodsWalker Maidana
309 views4 slides
Advanced REXX Programming Techniques by
Advanced REXX Programming TechniquesAdvanced REXX Programming Techniques
Advanced REXX Programming TechniquesDan O'Dea
9.5K views34 slides
Regular Expressions: JavaScript And Beyond by
Regular Expressions: JavaScript And BeyondRegular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And BeyondMax Shirshin
1.9K views93 slides

Similar to Rspamd symbols(20)

Hacking parse.y (RubyKansai38) by ujihisa
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)
ujihisa1.1K views
Hacking Parse.y with ujihisa by ujihisa
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisa
ujihisa854 views
Advanced REXX Programming Techniques by Dan O'Dea
Advanced REXX Programming TechniquesAdvanced REXX Programming Techniques
Advanced REXX Programming Techniques
Dan O'Dea9.5K views
Regular Expressions: JavaScript And Beyond by Max Shirshin
Regular Expressions: JavaScript And BeyondRegular Expressions: JavaScript And Beyond
Regular Expressions: JavaScript And Beyond
Max Shirshin1.9K views
Stata Programming Cheat Sheet by Laura Hughes
Stata Programming Cheat SheetStata Programming Cheat Sheet
Stata Programming Cheat Sheet
Laura Hughes1.4K views
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru... by ssuserd6b1fd
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
ssuserd6b1fd574 views
Gnu octave help book 02 of 02 by Arun Umrao
Gnu octave help book 02 of 02Gnu octave help book 02 of 02
Gnu octave help book 02 of 02
Arun Umrao7.3K views
JavaScript - An Introduction by Manvendra Singh
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh19.1K views
Hacking parse.y (RubyConf 2009) by ujihisa
Hacking parse.y (RubyConf 2009)Hacking parse.y (RubyConf 2009)
Hacking parse.y (RubyConf 2009)
ujihisa2.3K views
Matching with Regular Expressions by primeteacher32
Matching with Regular ExpressionsMatching with Regular Expressions
Matching with Regular Expressions
primeteacher32484 views
Stata cheatsheet programming by Tim Essam
Stata cheatsheet programmingStata cheatsheet programming
Stata cheatsheet programming
Tim Essam887 views

Recently uploaded

CHI-SQUARE ( χ2) TESTS.pptx by
CHI-SQUARE ( χ2) TESTS.pptxCHI-SQUARE ( χ2) TESTS.pptx
CHI-SQUARE ( χ2) TESTS.pptxssusera597c5
29 views33 slides
CHEMICAL KINETICS.pdf by
CHEMICAL KINETICS.pdfCHEMICAL KINETICS.pdf
CHEMICAL KINETICS.pdfAguedaGutirrez
8 views337 slides
MK__Cert.pdf by
MK__Cert.pdfMK__Cert.pdf
MK__Cert.pdfHassan Khan
8 views1 slide
String.pptx by
String.pptxString.pptx
String.pptxAnanthi Palanisamy
47 views24 slides
SEMI CONDUCTORS by
SEMI CONDUCTORSSEMI CONDUCTORS
SEMI CONDUCTORSpavaniaalla2005
20 views8 slides
Pull down shoulder press final report docx (1).pdf by
Pull down shoulder press final report docx (1).pdfPull down shoulder press final report docx (1).pdf
Pull down shoulder press final report docx (1).pdfComsat Universal Islamabad Wah Campus
10 views25 slides

Recently uploaded(20)

CHI-SQUARE ( χ2) TESTS.pptx by ssusera597c5
CHI-SQUARE ( χ2) TESTS.pptxCHI-SQUARE ( χ2) TESTS.pptx
CHI-SQUARE ( χ2) TESTS.pptx
ssusera597c529 views
13_DVD_Latch-up_prevention.pdf by Usha Mehta
13_DVD_Latch-up_prevention.pdf13_DVD_Latch-up_prevention.pdf
13_DVD_Latch-up_prevention.pdf
Usha Mehta10 views
A multi-microcontroller-based hardware for deploying Tiny machine learning mo... by IJECEIAES
A multi-microcontroller-based hardware for deploying Tiny machine learning mo...A multi-microcontroller-based hardware for deploying Tiny machine learning mo...
A multi-microcontroller-based hardware for deploying Tiny machine learning mo...
IJECEIAES12 views
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,... by AakashShakya12
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
AakashShakya1257 views
7_DVD_Combinational_MOS_Logic_Circuits.pdf by Usha Mehta
7_DVD_Combinational_MOS_Logic_Circuits.pdf7_DVD_Combinational_MOS_Logic_Circuits.pdf
7_DVD_Combinational_MOS_Logic_Circuits.pdf
Usha Mehta59 views
Machine Element II Course outline.pdf by odatadese1
Machine Element II Course outline.pdfMachine Element II Course outline.pdf
Machine Element II Course outline.pdf
odatadese17 views
Thermal aware task assignment for multicore processors using genetic algorithm by IJECEIAES
Thermal aware task assignment for multicore processors using genetic algorithm Thermal aware task assignment for multicore processors using genetic algorithm
Thermal aware task assignment for multicore processors using genetic algorithm
IJECEIAES30 views
9_DVD_Dynamic_logic_circuits.pdf by Usha Mehta
9_DVD_Dynamic_logic_circuits.pdf9_DVD_Dynamic_logic_circuits.pdf
9_DVD_Dynamic_logic_circuits.pdf
Usha Mehta28 views

Rspamd symbols

  • 2. WHAT ARE SYMBOLS AND RULES DEFINITIONS RULE SYMBOL SCORE GROUP DESCRIPTION WEIGHT * true/false OPTIONS Dynamic part Static part ∑ Results FLAGS
  • 3. WHAT ARE SYMBOLS AND RULES WHY DO WE NEED SYMBOLS RULE SYMBOL_ALLOW SYMBOL_DENY SYMBOL_UNKNOWN Either of symbols
  • 4. WHAT ARE SYMBOLS AND RULES WHY DO WE NEED SYMBOLS RULE MAP1 MAP2 MAP3 Multiple symbols
  • 5. WHAT ARE SYMBOLS AND RULES WHY DO WE NEED SYMBOLS RULE1 SYMBOL1 RULE2 Dependency
  • 6. WHAT ARE SYMBOLS AND RULES RULES ▸ Rules define what is executed: ▸ Regexps expression ▸ Lua code ▸ Plugin logic ▸ Each rule can be associated with one or many symbols ▸ Rule can depend on other rules identified by associated symbols ▸ Each rule can define the current dynamic weight (usually from 0 to 1)
  • 7. WHAT ARE SYMBOLS AND RULES SYMBOLS ▸ Symbols define meta-information of a rule: ▸ Name ▸ Static score ▸ Other data (description, group, flags, etc) ▸ Symbols can be: ▸ Normal: associated with exactly one rule ▸ Virtual: are not associated with rules but grouped with normal symbol) ▸ Callback: do not have name or score, just define common rule ▸ Special: have special purpose (e.g. composite symbols)
  • 9. SYMBOLS SYMBOLS GROUPS ▸ Groups join common symbols logically ▸ Groups can set joint limit for symbols scores enclosed ▸ Groups can be used in composite rules: ▸ SYMBOL5 && G:GROUP1 ▸ SYMBOL5 && (G:GROUP1 || !G:GROUP2)
  • 10. RULES EXPRESSIONS IN RULES ▸ Expressions are used in: ▸ Regexp rules ▸ Composite symbols ▸ Expressions have common syntax: ▸ Logic operations: AND (&&), OR (||), NOT (!) ▸ Braces ▸ Limit operation: A + B + C > 2 ▸ Elements are called atoms
  • 11. RULES REGEXP EXPRESSIONS ▸ Atoms are regular expressions (/re/flags): ▸ Header: Header=/re/H ▸ Mime (/P): scan text parts ▸ Body (/B): scan full undecoded body ▸ URL (/U): scan URLs found ▸ There is no order of regexps execution within an expression ▸ Same expressions are cached and executed once
  • 13. COMPOSITE EXPRESSIONS COMPOSITES OPERATIONS SYMBOL3 SYMBOL4 SYMBOL5 SYMBOL1 Group2 NOT SYMBOL6 AND AND SYMBOL1 SYMBOL3 Symbols to remove Stage 1: Check Stage 2: Remove symbols
  • 14. COMPOSITE EXPRESSIONS COMPOSITES STRUCTURE ▸ Composite atoms can include: ▸ Other symbols ▸ Groups (gr:) ▸ Other composites (with recursive references check) ▸ Composite operations can be the following: ▸ Remove symbol and weight (SYMBOL) ▸ Remove weight only (~SYMBOL) ▸ Remove symbol but preserve weight (-SYMBOL) ▸ Always remove symbol and weight (^SYMBOL)
  • 15. COMPOSITE EXPRESSIONS COMPOSITES OPERATION ▸ If any composite proposes that a symbol should NOT be removed, then it is NOT removed: ▸ A & ~B and C & B: B will NOT be removed because of the first rule, but its weight will be removed ▸ A & -B and C & ~B: neither weight, nor symbol B will be removed ▸ Removal could be forced by “^” symbol: ▸ A & ^B and C & -B: weight and symbol B are both removed
  • 16. PRACTICAL EXAMPLES A SIMPLE REGEXP EXPRESSION local reconf = config['regexp'] -- Define alias for regexp module -- Define a single regexp rule reconf['PRECEDENCE_BULK'] = { -- Header regexp that detects bulk email re = 'Precedence=/bulk/Hi', -- Default score score = 0.1, description = "Message marked as bulk", group = 'upstream_spam_filters' } rspamd.local.lua:
  • 17. PRACTICAL EXAMPLES A MORE COMPLEX EXAMPLE rspamd.local.lua: local reconf = config['regexp'] -- Define alias for regexp module -- Define encodings types -- /X is undecoded header local subject_encoded_b64 = 'Subject=/=?S+?B?/iX' local subject_encoded_qp = 'Subject=/=?S+?Q?/iX' -- Define whether subject must be encoded (contains non-7bit characters) local subject_needs_mime = 'Subject=/[x00-x08x0bx0cx0e-x1fx7f-xff]/X' -- Final rule reconf['SUBJECT_NEEDS_ENCODING'] = { -- Combine regexps re = string.format('!(%s) & !(%s) & (%s)', subject_encoded_b64, subject_encoded_qp, subject_needs_mime), score = 3.5, description = "Subject contains non-ASCII chars but it is not encoded", group = 'headers' }
  • 18. PRACTICAL EXAMPLES A MORE COMPLEX EXAMPLE rspamd.local.lua: local reconf = config['regexp'] -- Define alias for regexp module -- Define encodings types -- /X is undecoded header local subject_encoded_b64 = 'Subject=/=?S+?B?/iX' local subject_encoded_qp = 'Subject=/=?S+?Q?/iX' -- Define whether subject must be encoded (contains non-7bit characters) local subject_needs_mime = 'Subject=/[x00-x08x0bx0cx0e-x1fx7f-xff]/X' -- Final rule reconf['SUBJECT_NEEDS_ENCODING'] = { -- Combine regexps re = string.format('!(%s) & !(%s) & (%s)', subject_encoded_b64, subject_encoded_qp, subject_needs_mime), score = 3.5, description = "Subject contains non-ASCII chars but it is not encoded", group = 'headers' }
  • 19. PRACTICAL EXAMPLES A MORE COMPLEX EXAMPLE rspamd.local.lua: local reconf = config['regexp'] -- Define alias for regexp module -- Define encodings types -- /X is undecoded header local subject_encoded_b64 = 'Subject=/=?S+?B?/iX' local subject_encoded_qp = 'Subject=/=?S+?Q?/iX' -- Define whether subject must be encoded (contains non-7bit characters) local subject_needs_mime = 'Subject=/[x00-x08x0bx0cx0e-x1fx7f-xff]/X' -- Final rule reconf['SUBJECT_NEEDS_ENCODING'] = { -- Combine regexps re = string.format('!(%s) & !(%s) & (%s)', subject_encoded_b64, subject_encoded_qp, subject_needs_mime), score = 3.5, description = "Subject contains non-ASCII chars but it is not encoded", group = 'headers' }
  • 20. PRACTICAL EXAMPLES COMPOSITES EXAMPLE local.d/composites.conf: # Ignore forged recipients in case of mailing list composite "FORGED_RECIPIENTS_MAILLIST" { # MALLIST symbol is preserved expression = "FORGED_RECIPIENTS & -MAILLIST"; } # Ignore forged sender if a message has been forwarded composite "FORGED_SENDER_FORWARDING" { # Symbols from `forwarding` group are removed expression = "FORGED_SENDER & g:forwarding"; } # Ignore forged sender if a message has been from the mailing list composite "FORGED_SENDER_MAILLIST" { # Symbol 'FORGED_SENDER' is forced to be removed expression = "^FORGED_SENDER & -MAILLIST"; }
  • 21. PRACTICAL EXAMPLES COMPOSITES EXAMPLE local.d/composites.conf: # Ignore forged recipients in case of mailing list composite "FORGED_RECIPIENTS_MAILLIST" { # MALLIST symbol is preserved expression = "FORGED_RECIPIENTS & -MAILLIST"; } # Ignore forged sender if a message has been forwarded composite "FORGED_SENDER_FORWARDING" { # Symbols from `forwarding` group are removed expression = "FORGED_SENDER & g:forwarding"; } # Ignore forged sender if a message has been from the mailing list composite "FORGED_SENDER_MAILLIST" { # Symbol 'FORGED_SENDER' is forced to be removed expression = "^FORGED_SENDER & -MAILLIST"; }
  • 22. PRACTICAL EXAMPLES COMPOSITES EXAMPLE local.d/composites.conf: # Ignore forged recipients in case of mailing list composite "FORGED_RECIPIENTS_MAILLIST" { # MALLIST symbol is preserved expression = "FORGED_RECIPIENTS & -MAILLIST"; } # Ignore forged sender if a message has been forwarded composite "FORGED_SENDER_FORWARDING" { # Symbols from `forwarding` group are removed expression = "FORGED_SENDER & g:forwarding"; } # Ignore forged sender if a message has been from the mailing list composite "FORGED_SENDER_MAILLIST" { # Symbol 'FORGED_SENDER' is forced to be removed expression = "^FORGED_SENDER & -MAILLIST"; }
  • 23. PRACTICAL EXAMPLES COMPOSITES EXAMPLE local.d/composites.conf: # Ignore forged recipients in case of mailing list composite "FORGED_RECIPIENTS_MAILLIST" { # MALLIST symbol is preserved expression = "FORGED_RECIPIENTS & -MAILLIST"; } # Ignore forged sender if a message has been forwarded composite "FORGED_SENDER_FORWARDING" { # Symbols from `forwarding` group are removed expression = "FORGED_SENDER & g:forwarding"; } # Ignore forged sender if a message has been from the mailing list composite "FORGED_SENDER_MAILLIST" { # Symbol 'FORGED_SENDER' is forced to be removed expression = "^FORGED_SENDER & -MAILLIST"; }
  • 24. PRACTICAL EXAMPLES COMPOSITES EXAMPLE local.d/composites.conf: # Ignore forged recipients in case of mailing list composite "FORGED_RECIPIENTS_MAILLIST" { # MALLIST symbol is preserved expression = "FORGED_RECIPIENTS & -MAILLIST"; } # Ignore forged sender if a message has been forwarded composite "FORGED_SENDER_FORWARDING" { # Symbols from `forwarding` group are removed expression = "FORGED_SENDER & g:forwarding"; } # Ignore forged sender if a message has been from the mailing list composite "FORGED_SENDER_MAILLIST" { # Symbol 'FORGED_SENDER' is forced to be removed expression = "^FORGED_SENDER & -MAILLIST"; }