Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impossible for milter_headers to add a custom header #51

Open
dlatchx opened this issue Jan 10, 2024 · 2 comments
Open

impossible for milter_headers to add a custom header #51

dlatchx opened this issue Jan 10, 2024 · 2 comments

Comments

@dlatchx
Copy link

dlatchx commented Jan 10, 2024

rspamd has a module to insert custom headers : https://rspamd.com/doc/modules/milter_headers.html

But this filter only support a few hardcoded headers.

I think the problem is here :

/**
* Prefix auth headers to incoming mail in proper order.
*/
if len(authHeaders) > 0 {
hdrs := []string{
"ARC-Seal",
"ARC-Message-Signature",
"ARC-Authentication-Results",
"Authentication-Results"}
for _, h := range hdrs {
if authHeaders[h] != "" {
writeHeader(s, token, h, authHeaders[h])
}
}
}

Only the headers in hdrs will be inserted by the filter.

Here is an example of the headers that rspamd can return:

curl -s -X POST http://localhost:11333/checkv2 | jq .milter.add_headers
{
  "X-Spamd-Bar": {
    "value": "+++++++++++++++",
    "order": -1
  },
  "X-Spamd-Result": {
    "value": "default: True [15.00 / 15.00];\r\n\tCOMPLETELY_EMPTY(15.00)[]",
    "order": -1
  },
  "X-Rspamd-Action": {
    "value": "reject",
    "order": -1
  },
  "X-Spam-Status": {
    "value": "Yes, score=15.00",
    "order": -1
  },
  "Authentication-Results": {
    "value": "localhost;\r\n\tnone",
    "order": 1
  },
  "X-Rspamd-Server": {
    "value": "localhost",
    "order": -1
  },
  "X-Spam-Level": {
    "value": "***************",
    "order": -1
  }
}

I can rewrite this, but I'd like to know what is the rationale for this code:

How does the order matter ?
Does this matter for other headers (such as those given above) ?

@dlatchx
Copy link
Author

dlatchx commented Jan 10, 2024

Does the order matter -> yes, it's required by the RFC
https://github.com/rspamd/rspamd/blob/2e2aab12026b0cbd401a364a888d6ecdd5f8d5db/src/plugins/lua/arc.lua#L597-L605

It looks like rspamd's infrastructure for inserting headers in a specified order is very brittle, and it will be hard to fix properly.
So it looks like it we'll have to kip this manual ordering on our side for now.

@junaru
Copy link

junaru commented Apr 28, 2024

@dlatchx huge thanks!

Just wasted better part of the weekend trying to figure out why rspamd doesn't add my headers...

Confirming the pull requests works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants