headline-antidote 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. headline_antidote-0.1.0/LICENSE +21 -0
  2. headline_antidote-0.1.0/PKG-INFO +130 -0
  3. headline_antidote-0.1.0/README.md +105 -0
  4. headline_antidote-0.1.0/headline_antidote/__init__.py +21 -0
  5. headline_antidote-0.1.0/headline_antidote/article.py +994 -0
  6. headline_antidote-0.1.0/headline_antidote/browser_check.py +336 -0
  7. headline_antidote-0.1.0/headline_antidote/browser_visibility.py +501 -0
  8. headline_antidote-0.1.0/headline_antidote/css_cascade.py +2054 -0
  9. headline_antidote-0.1.0/headline_antidote/css_hiding.py +249 -0
  10. headline_antidote-0.1.0/headline_antidote/css_validity.py +2527 -0
  11. headline_antidote-0.1.0/headline_antidote/css_values.py +965 -0
  12. headline_antidote-0.1.0/headline_antidote/document_mode.py +178 -0
  13. headline_antidote-0.1.0/headline_antidote/html_tree.py +148 -0
  14. headline_antidote-0.1.0/headline_antidote/html_visibility.py +1655 -0
  15. headline_antidote-0.1.0/headline_antidote/media_queries.py +348 -0
  16. headline_antidote-0.1.0/headline_antidote/report_schema.json +1187 -0
  17. headline_antidote-0.1.0/headline_antidote/text_guard.py +949 -0
  18. headline_antidote-0.1.0/headline_antidote/unicode_data/DerivedCoreProperties.txt +13857 -0
  19. headline_antidote-0.1.0/headline_antidote/unicode_data/Scripts.txt +3231 -0
  20. headline_antidote-0.1.0/headline_antidote/unicode_data/confusables.txt +9862 -0
  21. headline_antidote-0.1.0/headline_antidote/unicode_data/manifest.json +20 -0
  22. headline_antidote-0.1.0/headline_antidote/unicode_tables.py +132 -0
  23. headline_antidote-0.1.0/headline_antidote/watchlists.py +15 -0
  24. headline_antidote-0.1.0/headline_antidote.egg-info/PKG-INFO +130 -0
  25. headline_antidote-0.1.0/headline_antidote.egg-info/SOURCES.txt +41 -0
  26. headline_antidote-0.1.0/headline_antidote.egg-info/dependency_links.txt +1 -0
  27. headline_antidote-0.1.0/headline_antidote.egg-info/requires.txt +11 -0
  28. headline_antidote-0.1.0/headline_antidote.egg-info/top_level.txt +1 -0
  29. headline_antidote-0.1.0/pyproject.toml +43 -0
  30. headline_antidote-0.1.0/setup.cfg +4 -0
  31. headline_antidote-0.1.0/tests/test_article.py +191 -0
  32. headline_antidote-0.1.0/tests/test_attacks.py +217 -0
  33. headline_antidote-0.1.0/tests/test_benchmark.py +174 -0
  34. headline_antidote-0.1.0/tests/test_browser_check.py +820 -0
  35. headline_antidote-0.1.0/tests/test_css_cascade.py +947 -0
  36. headline_antidote-0.1.0/tests/test_css_validity.py +876 -0
  37. headline_antidote-0.1.0/tests/test_html.py +363 -0
  38. headline_antidote-0.1.0/tests/test_html_parsing.py +264 -0
  39. headline_antidote-0.1.0/tests/test_performance.py +37 -0
  40. headline_antidote-0.1.0/tests/test_real_language.py +114 -0
  41. headline_antidote-0.1.0/tests/test_remaining_gaps.py +598 -0
  42. headline_antidote-0.1.0/tests/test_report.py +696 -0
  43. headline_antidote-0.1.0/tests/test_svg_text.py +584 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NoCritics
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: headline-antidote
3
+ Version: 0.1.0
4
+ Summary: Checks that the news headline an LLM reads is the text a human reader sees: homoglyphs, hidden HTML text, invisible characters.
5
+ Project-URL: Homepage, https://github.com/NoCritics/headline-antidote
6
+ Project-URL: Issues, https://github.com/NoCritics/headline-antidote/issues
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Topic :: Security
11
+ Classifier: Topic :: Text Processing :: Markup :: HTML
12
+ Requires-Python: >=3.11
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: lxml>=6.1.3
16
+ Requires-Dist: selectolax==1.0.2
17
+ Requires-Dist: tinycss2==1.5.1
18
+ Requires-Dist: cssselect2==0.10.1
19
+ Requires-Dist: trafilatura>=2.3.1
20
+ Provides-Extra: browser
21
+ Requires-Dist: playwright>=1.64.1; extra == "browser"
22
+ Provides-Extra: test
23
+ Requires-Dist: jsonschema>=4.26.0; extra == "test"
24
+ Dynamic: license-file
25
+
26
+ # headline-antidote
27
+
28
+ Checks that the text an LLM reads from a news page is the text a person sees on it.
29
+
30
+ Built against the attacks in Rizvani, Apruzzese and Laskov, *Adversarial News and Lost Profits: Manipulating Headlines in LLM-Driven Algorithmic Trading* (arXiv:2601.13082, IEEE SaTML 2026):
31
+
32
+ - look-alike letters in a company name ("Теsla" with a Cyrillic Т and е), so the headline is never linked to its stock;
33
+ - hidden text (`<span style="display:none">losses and layoffs</span>`), which the model reads and readers don't.
34
+
35
+ ## What it does
36
+
37
+ - Finds look-alike letters, invisible Unicode characters and bidi tricks, and links watched company names to their tickers. Real Russian, Greek, Arabic, CJK and other text is left alone.
38
+ - Reads HTML and CSS the way Chrome does and removes text a reader can't see: `display:none`, zero size or opacity, off-screen, clipped, covered, or the same colour as the background.
39
+ - Picks the real headline (the `<h1>` that matches the page's titles) and the visible article body.
40
+ - Compares the headline with the feed and metadata titles, which page CSS and scripts can't change.
41
+ - When HTML and CSS aren't enough to decide (about 15% of real pages), renders the page in headless Chrome.
42
+ - Gives each result a verdict (`pass`, `review`, `quarantine`) and flags with evidence, as objects or JSON.
43
+
44
+ It doesn't fetch pages.
45
+
46
+ ## Results
47
+
48
+ An attack gets through when the model gets the hidden text and headline-antidote says `pass`.
49
+
50
+ ![Attacks that reach the model: 17 example pages](https://raw.githubusercontent.com/NoCritics/headline-antidote/master/benchmark/charts/example_pages.png)
51
+
52
+ These are the 17 pages headline-antidote was built against. The real pages below are the harder test.
53
+
54
+ ![Attacks that reach the model: real news pages](https://raw.githubusercontent.com/NoCritics/headline-antidote/master/benchmark/charts/real_pages.png)
55
+
56
+ The [gallery](https://github.com/NoCritics/headline-antidote/blob/master/benchmark/README.md) shows each example page and what each scraper got from it.
57
+
58
+ ## Install
59
+
60
+ Python 3.11 or later.
61
+
62
+ ```
63
+ pip install headline-antidote
64
+ pip install "headline-antidote[browser]" # adds the browser check; drives the installed Google Chrome
65
+ ```
66
+
67
+ ## Use
68
+
69
+ ```python
70
+ from headline_antidote import HeadlineAntidote
71
+
72
+ guard = HeadlineAntidote({"TSLA": ["Tesla"], "GOOGL": ["Alphabet", "Google"]})
73
+
74
+ article = guard.extract_article(page_html, feed_title=rss_title)
75
+ article.verdict # "pass", "review" or "quarantine"
76
+ article.headline # the visible headline
77
+ article.body # the visible article text
78
+ article.flags
79
+
80
+ if article.needs_browser_check:
81
+ from headline_antidote.browser_visibility import BrowserVerifier
82
+ with BrowserVerifier() as verifier: # keep one open across pages
83
+ article = guard.verify_article_in_browser(article, page_html, page_url, verifier)
84
+
85
+ result = guard.analyze("Теsla shares surge") # plain text, such as a feed title
86
+ result.verdict # "quarantine"
87
+ result.clean_text # "Tesla shares surge"
88
+ result.tickers # ["TSLA"]
89
+ ```
90
+
91
+ Give the model only `headline` and `body`, or `clean_text`. What to do with each verdict:
92
+
93
+ - `pass`: use it.
94
+ - `review`: lower its weight, or wait for a second source.
95
+ - `quarantine`: drop it and alert.
96
+
97
+ ## JSON report
98
+
99
+ ```python
100
+ import json
101
+ print(json.dumps(article.to_dict(), indent=2, ensure_ascii=False))
102
+ ```
103
+
104
+ ```json
105
+ {"schema_version": "1.0", "report_type": "text", "verdict": "quarantine",
106
+ "text_as_written": "Tesla shares surge", "text_cleaned": "Tesla shares surge", "tickers": ["TSLA"],
107
+ "flags": [{"category": "hidden_html_text", "severity": "high", "field": null, "flagged_text": "plunge",
108
+ "evidence": {"cause": "tiny_font", "css": "font-size:0"}, "start": null, "end": null}]}
109
+ ```
110
+
111
+ This is the report for `<h1>Tesla shares <span style="font-size:0">plunge</span> surge</h1>`. The schema ships as `report_schema.json`, and [docs/report_format.md](docs/report_format.md) describes every field.
112
+
113
+ Don't give the report itself to an LLM. Its strings come from the page, and an attacker may control the page.
114
+
115
+ ## More
116
+
117
+ The [guide](docs/guide.md) covers scraper setup, external stylesheets, the browser check, every flag, test results and known limits.
118
+
119
+ ## Tests
120
+
121
+ ```
122
+ pip install ".[browser,test]"
123
+ python -X utf8 -m unittest discover -s tests -t .
124
+ ```
125
+
126
+ Without the extras, the Chrome and schema tests are skipped.
127
+
128
+ ## Licence
129
+
130
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,105 @@
1
+ # headline-antidote
2
+
3
+ Checks that the text an LLM reads from a news page is the text a person sees on it.
4
+
5
+ Built against the attacks in Rizvani, Apruzzese and Laskov, *Adversarial News and Lost Profits: Manipulating Headlines in LLM-Driven Algorithmic Trading* (arXiv:2601.13082, IEEE SaTML 2026):
6
+
7
+ - look-alike letters in a company name ("Теsla" with a Cyrillic Т and е), so the headline is never linked to its stock;
8
+ - hidden text (`<span style="display:none">losses and layoffs</span>`), which the model reads and readers don't.
9
+
10
+ ## What it does
11
+
12
+ - Finds look-alike letters, invisible Unicode characters and bidi tricks, and links watched company names to their tickers. Real Russian, Greek, Arabic, CJK and other text is left alone.
13
+ - Reads HTML and CSS the way Chrome does and removes text a reader can't see: `display:none`, zero size or opacity, off-screen, clipped, covered, or the same colour as the background.
14
+ - Picks the real headline (the `<h1>` that matches the page's titles) and the visible article body.
15
+ - Compares the headline with the feed and metadata titles, which page CSS and scripts can't change.
16
+ - When HTML and CSS aren't enough to decide (about 15% of real pages), renders the page in headless Chrome.
17
+ - Gives each result a verdict (`pass`, `review`, `quarantine`) and flags with evidence, as objects or JSON.
18
+
19
+ It doesn't fetch pages.
20
+
21
+ ## Results
22
+
23
+ An attack gets through when the model gets the hidden text and headline-antidote says `pass`.
24
+
25
+ ![Attacks that reach the model: 17 example pages](https://raw.githubusercontent.com/NoCritics/headline-antidote/master/benchmark/charts/example_pages.png)
26
+
27
+ These are the 17 pages headline-antidote was built against. The real pages below are the harder test.
28
+
29
+ ![Attacks that reach the model: real news pages](https://raw.githubusercontent.com/NoCritics/headline-antidote/master/benchmark/charts/real_pages.png)
30
+
31
+ The [gallery](https://github.com/NoCritics/headline-antidote/blob/master/benchmark/README.md) shows each example page and what each scraper got from it.
32
+
33
+ ## Install
34
+
35
+ Python 3.11 or later.
36
+
37
+ ```
38
+ pip install headline-antidote
39
+ pip install "headline-antidote[browser]" # adds the browser check; drives the installed Google Chrome
40
+ ```
41
+
42
+ ## Use
43
+
44
+ ```python
45
+ from headline_antidote import HeadlineAntidote
46
+
47
+ guard = HeadlineAntidote({"TSLA": ["Tesla"], "GOOGL": ["Alphabet", "Google"]})
48
+
49
+ article = guard.extract_article(page_html, feed_title=rss_title)
50
+ article.verdict # "pass", "review" or "quarantine"
51
+ article.headline # the visible headline
52
+ article.body # the visible article text
53
+ article.flags
54
+
55
+ if article.needs_browser_check:
56
+ from headline_antidote.browser_visibility import BrowserVerifier
57
+ with BrowserVerifier() as verifier: # keep one open across pages
58
+ article = guard.verify_article_in_browser(article, page_html, page_url, verifier)
59
+
60
+ result = guard.analyze("Теsla shares surge") # plain text, such as a feed title
61
+ result.verdict # "quarantine"
62
+ result.clean_text # "Tesla shares surge"
63
+ result.tickers # ["TSLA"]
64
+ ```
65
+
66
+ Give the model only `headline` and `body`, or `clean_text`. What to do with each verdict:
67
+
68
+ - `pass`: use it.
69
+ - `review`: lower its weight, or wait for a second source.
70
+ - `quarantine`: drop it and alert.
71
+
72
+ ## JSON report
73
+
74
+ ```python
75
+ import json
76
+ print(json.dumps(article.to_dict(), indent=2, ensure_ascii=False))
77
+ ```
78
+
79
+ ```json
80
+ {"schema_version": "1.0", "report_type": "text", "verdict": "quarantine",
81
+ "text_as_written": "Tesla shares surge", "text_cleaned": "Tesla shares surge", "tickers": ["TSLA"],
82
+ "flags": [{"category": "hidden_html_text", "severity": "high", "field": null, "flagged_text": "plunge",
83
+ "evidence": {"cause": "tiny_font", "css": "font-size:0"}, "start": null, "end": null}]}
84
+ ```
85
+
86
+ This is the report for `<h1>Tesla shares <span style="font-size:0">plunge</span> surge</h1>`. The schema ships as `report_schema.json`, and [docs/report_format.md](docs/report_format.md) describes every field.
87
+
88
+ Don't give the report itself to an LLM. Its strings come from the page, and an attacker may control the page.
89
+
90
+ ## More
91
+
92
+ The [guide](docs/guide.md) covers scraper setup, external stylesheets, the browser check, every flag, test results and known limits.
93
+
94
+ ## Tests
95
+
96
+ ```
97
+ pip install ".[browser,test]"
98
+ python -X utf8 -m unittest discover -s tests -t .
99
+ ```
100
+
101
+ Without the extras, the Chrome and schema tests are skipped.
102
+
103
+ ## Licence
104
+
105
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,21 @@
1
+ from .text_guard import (
2
+ HIGH,
3
+ LOW,
4
+ MEDIUM,
5
+ EntityMention,
6
+ Flag,
7
+ GuardResult,
8
+ HeadlineAntidote,
9
+ )
10
+ from .watchlists import PAPER_WATCHLIST
11
+
12
+ __all__ = [
13
+ "HIGH",
14
+ "LOW",
15
+ "MEDIUM",
16
+ "EntityMention",
17
+ "Flag",
18
+ "GuardResult",
19
+ "HeadlineAntidote",
20
+ "PAPER_WATCHLIST",
21
+ ]