| Age | Commit message (Collapse) | Author | Lines |
|
Keep the SMTPUTF8 suite alongside the new ACISM, URL and SMTP address parser suites in the C++ test runner.
|
|
The Lua method took the userdata itself for the memory pool,
while the userdata only holds a pointer to it. The converted name
was then allocated in that bogus pool, which corrupted the heap
and crashed a worker a moment later.
It needs a domain with 8-bit characters and a pool argument, so
it was reachable from the arc module, which passes the task pool
since 71d34a6f2 when `adjust_dmarc` is used with a map of signers.
|
|
A keep-alive connection is put to the pool and its parser is
started anew when a reply is complete. Bytes after the reply
in the same read, or the end of a stream that ends a reply
with no length, were then an error of a request that was
finished: the error handler of lua_http ran on freed data.
What follows a delivered reply is no error of that request,
and such a connection is closed, not reused.
The pool of idle connections:
- The key had no word of TLS verification: a request that
wants the certificate verified got a connection made with
`no_ssl_verify`. These are pooled apart.
- A connection is reused only for the address it was made
to. The key is a host name, which a Host header sets, so
a request to one address went over a connection to
another, and `forbid_local` was checked against an address
that was not the one in use.
- A connection is checked for bytes to read and for the end
of the stream when it is taken: with a busy event loop a
reply that a server sent late was read as the reply to the
next request.
- An interim reply (100, 103) is not the answer: the final
one is read after it.
- The idle time that a server asks for is capped at 300 s,
128 idle connections are kept for a key by default, and
`close` in any Connection header ends the connection.
- Limits, timeouts and the HTTPCrypt key of the peer of one
request no longer stay on the connection for the next.
|
|
A reply of a type that was not known (a map, a set, a double
of the newer protocol) pushed no value: inside an array the
next value went to a wrong slot of the stack and the worker
crashed, at the top level the callback was not called.
Arrays nested deep enough overflowed the Lua stack. Every
reply gives exactly one value now, a map as its keys and
values in a row, and nesting stops at 32 levels.
A connection on which a caller ran SELECT, MULTI, WATCH,
SUBSCRIBE and the like is closed when released: the next
user of a pooled one got that database or transaction.
`add_cmd` on a connection that was already released called
hiredis with no context, and a request with no command took
the length of a NULL string. `connect_sync` ignored
`no_pool`.
Sentinel: an address from a reply becomes a part of a list
of servers, so it must be an address or a host name and
nothing else, and no more than 64 masters are followed. The
debug log of the parameters of a server had its password.
|
|
169.254.0.0/16 was refused only through `local_addrs`: with
that option set to the networks of an installation, a
redirect could lead to such an address.
|
|
`a/24//64` was not read: after the IPv4 length one slash of
the two was taken and the other one was a bad length, so the
term was dropped and the senders of such a domain got the
result of its `all`. `//64` alone worked. The second slash is
required and consumed, and `a/24/64` is not a term.
`rspamadm dnstool spf-flatten` went by the old order of the
elements of a record: it stopped taking networks at the first
`all`, which is now the one of the first include, and wrote
out the `all` of each include. The elements that only end an
include have a `jump` field in Lua, and the tool skips them.
|
|
All the limits of `archive.unpack` were off unless set, and
the only caller in the tree sets them. Without options the
output is now limited to 1 GiB and the headers to a million;
zero still means no limit.
The filters are the ones the library does itself: "all" of
them includes those that run a program of the system (grzip,
lrzip, lzop) on the data.
A number as a key of `files` was converted to a string in
place while the table was walked, which breaks `lua_next`.
|
|
The option was registered with the offset of `max_word_len`
and the size of a pointer: setting it changed the limit of a
word, zeroed `words_decay` next to it, and left the limit of
an HTML part at its default.
Also: `textpart:filter_words(re, 'full')` aborted on a part
with an url, whose placeholder is a word with no normalized
text, as the regexp functions assert on the pointer before
they look at the length; and a custom tokenizer went back in
the text when two exceptions overlap.
|
|
A long text part is represented by its first words and a
sample of the rest, or by none of the rest when it is long
enough, and a message has a budget of words for all of its
parts. Nothing told that either had happened: statistics,
fuzzy hashes and rules on words see a message that is built
around these limits as they see any other.
The part now carries a flag for each case, `get_stats` of a
text part has `words_sampled` and `words_truncated`, and the
TEXT_WORDS_TRUNCATED symbol (no weight) reports them. The
limits are not changed.
Two defects in what goes into the words are fixed on the way.
The places of links in an HTML part were kept as offsets into
the text before zero width characters and line ends are
removed from it, while the words are taken after that: each
character removed before a link moved its placeholder over the
visible words that follow. And a zero width character at the
start of a line was counted but left in place, where it
became a word of its own.
|
|
Every record of the answer section went to the consumer,
whatever name owned it: a reply to a TXT query for one name
could carry a record of another name, which SPF, DKIM or DMARC
then read as the answer. The records kept now are those owned
by the name asked for, or by a name that a CNAME among the
accepted ones leads to, in any order.
A TCP frame that announces no data left the read state of the
channel in the middle of a frame, as the state was reset only
when a buffer was there: every later reply over TCP failed
until a restart, and there is one TCP channel per server.
A zero byte in a name or in a TXT record cut the string short
for its readers, and a dot inside of a label split it in two;
both are replaced in what is handed over.
In the Lua resolver a PTR request for a string that is no
address released a reference it did not hold, and without a
pool the address itself was asked for instead of its reverse
name.
|
|
The elements of a flattened record were sorted, by a comparator
that was not an order at that, so the first match was not the
first term that matches: `-ip4:1.2.3.4 +ip4:1.2.3.0/24 -all`
let 1.2.3.4 pass, and so did `-all ip4:1.2.3.4`. The order of
the record is kept now.
An include was copied in with the qualifiers of its own terms,
and the one of the include was dropped: `-include:x` passed
what x passes, and a fail inside of x was a fail of the outer
record. A match inside of an include now gives the qualifier of
the include when the included record passes, and goes on after
the include otherwise. A redirect is applied after the
mechanisms, wherever it stands.
The value of a macro comes from the sender (local part, HELO),
and a slash in it was read as the prefix length of the term
after the expansion: `a:%{l}.example` with a local part of
`host/0` passed any address. `a//64` gave IPv4 a length of
zero, `a/65536` wrapped to zero, and garbage after a length was
ignored; such a term is not used now.
Mechanism names are compared in full (`+allfoo` was `+all`),
and so is the version (`v=spf10` was accepted). Macros and
`ptr` use the address that the record is checked for, which
with `external_relay` is not the one of the connection. A
flattened record has at most 8192 elements and is cached for a
week at most; a negative TTL is not a TTL.
|
|
The option refused loopback, link-local and the networks of
`local_addrs`. 0.0.0.0 and `::` were let through, and a connect
to either of them reaches the local host, where the controller
trusts 127.0.0.1 and ::1. Also refused now: the rest of
0.0.0.0/8, the shared space 100.64.0.0/10, 192.0.0.0/24,
198.18.0.0/15, multicast and the reserved top of IPv4, unique
local and multicast IPv6, and any of these or of the local ones
as an IPv4 address inside of an IPv6 one, mapped or behind the
NAT64 prefix.
|
|
An element with both `href` and `xlink:href` gave the one that
stands first, while a browser takes `href`. Tabs and line ends
are removed from an url before its scheme is read, as they are
in a browser: `java	script:` was no script, and a link or a
data url written this way was not seen.
A style sheet is scanned whatever its size, in pieces: 64K of
padding hid an import after it. Presentation attributes with an
url are scanned as styles are. The text of a script is put
together before its words are looked for, as a comment or a
CDATA section splits it.
Text or links over a limit are left out and the document is
read to its end, with a flag for what was cut: it failed as a
whole, scripts and all, also for an image that came after one
that had used up the budget of the message.
|
|
A relationship target that starts with a slash is a part name
from the root of the package, a valid form that some producers
write; it was refused, and the package with it.
A story that cannot be parsed is left out and counted, with
what was read of it kept. One such part, or one made so, took
away the text and the links of the whole document.
The XML scanner takes names with letters outside of ASCII and
the DEL character in a text, both of which a document may
hold. An extra pop after the limits were read is removed.
|
|
With `ignore_case` the names in `files` select the members
whatever the case of their ASCII letters, as the names of the
parts of an OOXML package are matched by the applications.
|
|
The codes of a simple font are one byte each, whatever the
codespace of its /ToUnicode cmap says, and producers do declare
a two byte codespace for such fonts: the text was then read two
bytes at a time and came out as a few stray letters. The builder
has a mode for the cmap of a simple font, where a code that the
cmap leaves out goes through the encoding of the font, and can
tell how many codes a run of bytes holds.
The output buffer asked for the exact size on every piece of
text, which an implementation that allocates what it is asked
for turns into a copy of the buffer each time; it doubles now.
A /Differences array no longer counts its codes past 255.
|
|
A `z` of ASCII85 stands for four zero bytes, while the output
was sized for five characters per four bytes: data with a fifth
of zeroes in it failed to decode. The buffer accounts for them
now, and the function takes an optional limit of the output.
`util.inflate` logged an error for every stream it could not
read. Such streams come from the files that are parsed, by the
thousand in one pdf if a sender wishes so: the error is now the
second value returned, for the caller to deal with.
|
|
`archive.unpack` reads an archive through any filter that
libarchive knows, so a zip inside an xz or bzip2 stream passed
for a package. Such a stream cannot be seeked: it is
decompressed in full to walk over the members, skipped ones
included, with no limit on them and no deadline. A message of
14K made the worker decompress 48M.
The new `filters = false` option refuses a wrapped archive,
and the OOXML handler sets it: a package is a plain zip.
|
|
`url.create` with a text that has no url returned the text as
if it was an url, and wrote the flags given into it;
`set_redirected` with such a string raised an error. Both looked
at the type of the stack top, which is an argument when nothing
is found.
`task:inject_url` dereferenced a null pointer when its third
argument was userdata other than a mime part. The length of the
`callto` scheme was the one of `tel`.
|
|
`get_redirected` was an alias of `get_phished`: both returned
the linked url whatever it was, so the target of a redirect was
reported as the phished url and the text of a link as a redirect
target. Each of them now answers by the flags of the url; a
redirect set later replaces the shown url, so such an url has no
phished one.
|
|
The parts of an url are stored decoded, so `%0d%0a` in a path
came out of `to_http` as a raw line break, in a string that is
meant for a request line. Control characters and spaces are
percent-encoded again.
The buffer for an url with userinfo is sized by what is written
to it and is freed: it leaked on every call.
|
|
Over max_lua_urls, task:get_urls() kept each url with a chance
taken from the size of the whole set, with the urls that the call
filters out: email addresses added to a message made its links
disappear from the rules. The number of urls that pass the filter
of the call is counted first, and exactly the limit of them is
drawn when there are more. The draw is seeded with a value of
the process, so a sender cannot tell which urls are kept.
Also: the plain array of protocols was read from the task and not
from the table, so it was ignored; sort = false sorted; and the
comparison of two urls returned a number, which table.sort does
not take.
|
|
Rules read a limited number of archive names: CHECK_ARCHIVES the first
10, mime_types, multimap and the scanners 1000. A zip lists other
names of its files right after them (Unicode Path), and the names of
its local headers after its directory, so names crowded files out:
nine harmless names of a first file pushed a second payload.exe out
of CHECK_ARCHIVES, and renamed local headers pushed out a file that
only a local header names.
get_files(n) and get_files_full(n) now read the first n files of the
directory and the first n files of the local headers, each with the
other names listed right after it, which are flagged
RSPAMD_ARCHIVE_FILE_SAME_ENTRY. The reads stay bounded, as an entry
has at most 9 such names.
|
|
An unquoted attribute value with a quote in it is read as a link up to
the quote (href=3D"... of undecoded quoted-printable is no link to
that site), but browsers go to the whole value, which the rewrite
replaces. The policy got the part before the quote, so the URL it
returned dropped the rest: href=https://example.org/reset?token=abc"def
lost its "def. The policy and task:get_html_urls() now get the whole
value as browsers read it, the part after the quote read on its own
(NUL bytes, character references). The docs say that this value may
differ from the text of task:get_urls().
|
|
A zip lists its files twice, in its directory and in a local header
before each file's data, and readers do not agree on which they show:
bsdtar and macOS go by local headers, 7-Zip lists the local headers
that no directory record names. rspamd listed the directory only, so
a directory naming readme.txt hid a payload.exe local header, and the
files of an archive whose directory was not found, or was a fake one,
were not listed.
Readers also show the Info-ZIP Unicode Path extra field (0x7075) in
place of the name when its CRC is that of the name, or of the Unicode
Path before it (bsdtar), whatever its version.
The local headers walked and the Unicode Paths are now listed as well.
As these are most often other names of a file listed already, they are
flagged as aliases (`alias` in get_files_full), and rules that count
the files of an archive (SINGLE_FILE_ARCHIVE_WITH_EXE, the single-file
checks of mime_types) skip them, while the extension checks see them.
At most max_archive_files distinct local headers are kept, and names
are converted once.
|
|
Browsers load the src of iframe, frame, embed, audio, video, source
and track elements and ignore any href there. rspamd read only their
href, so <iframe src=evil> was never extracted and <iframe href=good
src=evil> showed good only. Their src is now their destination, and
href a plain attribute.
URL rewriting takes the same attribute (html_tag::clickable_attr): the
src of images, frames and media, else href, xlink:href of an SVG link
without one, then src. Rewrite candidates keep the tag id, not the tag.
|
|
resolve_part_name validated the segments of a relationship target,
then built the part name with rspamd_normalize_path_inplace, which
follows URL rules: it treats names such as "..." or "..x" in ways
that differ from the check. The part name is now built from the
validated segments themselves, where only "." and ".." are dot
segments, and a target ending in "." or ".." names no part.
|
|
Errors were not detected with ZSTD_isError, the output buffer leaked on errors
and the stream was left in an error state. A truncated frame made
decompression grow the output forever: it now grows only when the output is
full, and truncated input is an error.
|
|
task:set_recipients with the rewrite flag freed the wrong list and leaked the
replaced one. task:set_from overwrote the original envelope sender instead of
keeping it next to the rewritten one, and leaked the previous rewrite. Imported
addresses are sized for the whole user@domain.
|
|
Encoding delimiters when an option is inserted altered the values
seen by regexps, composites and multimap and littered X-Spamd-Result
with %25 and %2C. Options are now stored as is (only invalid
characters become U+FFFD); exporters that join options
(X-Spamd-Result, X-Virus, metadata_exporter, ClickHouse and the
symbols log line) percent-encode an option only when it contains one
of `[]{};,`, together with `%` for unambiguous decoding.
Plugins that previously joined several values into one
comma-separated option (asn, reputation, rbl, dmarc, content rules,
MULTIPLE_UNIQUE_HEADERS) now insert them as separate options.
Issue: #6344
|
|
Pass the complete connection table through Lua request builders and decode credentials, database and TLS settings once at the C boundary. Reuse the decoder and connection options in fuzzy storage, retain legacy flat callers, and keep borrowed Lua strings rooted until the pool copies them.
Cover all Lua forwarding paths, configuration precedence, database aliases, invalid nested options and string ownership with regression tests.
|
|
This is a much subtler ruleset for addresses than the one in RFC 6532,
see eai_from_bidi.eml for an example.
|
|
|
|
|
|
|
|
Validate SVG magic candidates as complete documents so embedded SVG
cannot suppress HTML parsing and URL extraction. Reject extra roots
and outside text, and enforce the raw input limit before conversion.
Scan CSS targets in one forward pass with deadline checks. Share the
effective timeout between the XML scanner and SVG handler. Add tests
for detection, HTML URLs, UTF-16 limits and CSS cancellation.
Fixes: #6332
|
|
[Fix] Resolve HTTP upstreams for hosts without public suffix
|
|
[Fix] short writes in task:store_in_file
|
|
|
|
Add a direct Lua URL parsing API with an explicit upstream mode. Use the existing parser for configured HTTP endpoints instead of a Lua authority fallback, and preserve IPv6 brackets when creating upstreams.
Keep the GPT configuration guard and cover endpoint components before and after TLD initialization, invalid endpoints, and actual IPv4/IPv6 upstream addresses and ports.
|
|
[Fix] Html/Url: stop hiding content that browsers show (#6321)
|
|
Several tokenizer states kept going past the point where browsers stop,
hiding the rest of the part (tags, links, text) from the scan:
- `<![CDATA[` and any `<![` with unbalanced brackets ran until the
brackets balanced; browsers take them as a bogus comment ending at the
first `>`. CDATA in SVG/MathML ends there too, as our tree cannot tell
foreign content reliably. CDATA in HTML content sets the new
`cdata_in_html` property
- comments ignored the `--!>` terminator
- raw text ended at any plausible end tag, but not at its own one with
a tab or long attributes; it now ends exactly at its own end tag.
title, textarea, xmp, iframe, noembed, noframes and plaintext are raw
text as in browsers, so a comment inside them no longer swallows what
follows; noscript is markup, as mail clients run no scripts
- input ending inside a comment, declaration or partial tag lost the
text after the last child of the open elements
Also `<!-x>`, `</ x>`, `</>`, `<!-->` and `<?>` no longer leak into the
text, and an out-of-bounds read in the comment start state is fixed.
Issue: #6321
|
|
Add rspamd_write_all(), which loops over short and interrupted writes,
and use it in rspamd_text:save_in_file() and the rsa/cryptobox
signature savers: they reported success for truncated files.
save_in_file() also closed a caller-supplied fd on a write error, so
the caller's own close (e.g. in the AV scanners' destructors) hit an
already closed and possibly reused descriptor. Now it only closes, and
unlinks on failure, the files it has created itself.
|
|
With the default parse mode a missing `mode` key was reset to 0, so
the table form created files with 0000 permissions instead of the
documented 0600. Parse with IGNORE_MISSING to keep the initialisers,
and test the default mode for both `filename` and `tmpmask`.
|
|
A missing `B` key under RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING did
not consume its va_arg, so every following key was written through
the wrong pointer. No caller combined the two until now.
|
|
|
|
has_pre_result returned the action type, which is `custom` for every
custom action. It now returns the name, as get_metric_action does, and
a fifth value with the flags in the format set_pre_result accepts.
With a true argument, it returns the pre-result that selects the action
and the reply instead of the first one, as a least result may head the
list. The score is left as it was.
|
|
The table form parsed its keys with RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT,
which writes 0 for a missing `priority`. So force_actions and spamtrap
recorded their results at low instead of normal, unlike the positional
form. Flags were also matched as an else-if chain, so
`least,no_smtp_message` only set `least`.
|
|
A rule whose action was already selected by the score was skipped before
it could record a passthrough result, so a critical rule could be
overridden by a later normal one. Once any rule sets a priority, such
rules now record their result with process_all implied, so the scan is
not cut short. Without priorities the old shortcut is kept.
Store the composite flag on composite symbols in the symcache and drop
the workaround in lua_config:get_symbol_flags(), so the flag lists
report it directly.
|
|
- Fix has_composite_atom(): get_symbol_flags() returns an array of flag
names, not a keyed map; iterate it correctly instead of testing a
non-existent `.composite` field.
- lua_config: get_symbol_flags() stripped the SYMBOL_TYPE_COMPOSITE bit
before returning flags to Lua; restore it so composite detection works.
- Add an optional `priority` rule setting (low/normal/high/critical or
0-3) to arbitrate which of several matching rules' passthrough result
wins, with validation, range clamping, and a warning when combined
with `least`.
- Register rules in a stable, name-sorted order instead of relying on
UCL's unspecified pairs() iteration order.
- Expand functional tests: composite-triggered postfilter promotion,
priority ordering (named, numeric, mixed main/postfilter stages), and
priority validation warnings.
Note: a rule matching on a composite can still be starved if an earlier
pre-result was set without `process_all`, since that suppresses
composite evaluation entirely; set `process_all = true` on the rule
that fires first.
|