Commit Graph

588 Commits

Author SHA1 Message Date
Drew DeVault 1258f0e418 flask.py: drop now-removed map.charset field 2024-04-11 13:36:26 +02:00
Drew DeVault 8c9fb045f0 srht.markdown: bump version to 17 2024-04-11 10:54:45 +02:00
toastal 0318e32f18 sections & asides should be treated similar to divs 2024-04-11 10:54:35 +02:00
toastal b827d95669 time should support datetime 2024-04-11 10:54:35 +02:00
toastal 6c8adf22ba blockquotes & qs allow cite for citation 2024-04-11 10:54:35 +02:00
toastal a742952349 bdo allows overriding the direction 2024-04-11 10:54:34 +02:00
toastal 6ff7c110a3 abbrs without titles aren’t terribly useful 2024-04-11 10:54:34 +02:00
toastal cfef06e22a allow any elements to have an ID
useful for ARIA labels & linking to particular elements/sections
2024-04-11 10:54:33 +02:00
toastal e1aafaa236 allow more global attributes for accessibility 2024-04-11 10:54:33 +02:00
toastal b74e54488f allow more elements for semantic, accessible, multilingual markup 2024-04-11 10:54:32 +02:00
Conrad Hoffmann 8ee2f5b7f8 flask: stop using deprecated code
The entire werkzeug.urls module has been deprecated for a while and was
removed entirely in werkzeug 3.0, which will be in the next Alpine
release.

See also:

- 53782a0a97
- https://github.com/pallets/werkzeug/pull/2768
2024-04-11 10:38:36 +02:00
Conrad Hoffmann 57ee342790 Preparations for PEP440 support
Currrently, builds for patches are broken because the version numbers
generated for them are not valid according to PEP 440 [1].

Previous attempts [2] have shown that this cannot be solved in a single
commit (needs coordination with sr.ht-apkbuilds), so here is an attempt
at preparing this repo for a switch without breaking anything.

The grand plan is roughly:

1. Add a pyproject.toml without touching setup.py (this commit)
2. Switch APKBUILD from `python setup.py build` to `python -m build`
3. Reduce setup.py to a stub, encoding all relevant information in
   pyproject.toml

With this commit, this module can be build with both `python setup.py
build` and `python -m build`, if, _and only if_ the PKGVER environment
variable is set, which is true for all our tooling.

As the version passed in via the environment is still not
PEP440-compatible, packaging non-tagged versions will remain broken
until step three above is executed.

The .gitattributes and .git_archival files are included for the future
setup. Since packages are built from `git-archive` tarballs, the commit
information has to be transported into the tarballs. The setuptools-scm
package specifies a mechanism for this [3]. Note, that in order to avoid
a hilarious bug [4] the checked in `.git_archival.txt` differs from the
template found in the documentation. The git version on git.sr.ht is new
enough that the `describe-name` will be expanded, and if present it is
the only information that setuptools-scm really requires.

[1] https://peps.python.org/pep-0440
[2] https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/50784
[3]: https://setuptools-scm.readthedocs.io/en/latest/usage/#git-archives
[4]: https://github.com/pypa/setuptools_scm/issues/806
2024-04-11 10:38:33 +02:00
Ersei Saggi 7b45163d8a Do not inject dir=auto using BeautifulSoup 2024-04-11 10:38:33 +02:00
Drew DeVault af24a3f16e srht.webhook: missed an import 2024-03-20 16:39:09 +01:00
Drew DeVault 91af4dd3bf .builds/alpine.yml: update to 3.19 2024-03-20 16:27:01 +01:00
Drew DeVault 26438e80a8 srht.webhook: fix SQLalchemy usage 2024-03-20 16:24:59 +01:00
Drew DeVault 022492145b .builds: drop debian, arch 2024-02-09 10:19:59 +01:00
Conrad Hoffmann bb005f2b38 config: allow spreading config over multiple files
This commit enables spreading the config in /etc/sr.ht - and, crucially,
_only_ in /etc/sr.ht - over multiple .ini files.

As before, if a file ./config.ini is found, it (and only it) is loaded
and any config in /etc is ignored.

Spreading the config over multiple files will make it much easier to
create containerized versions, where e.g. different secrets can be made
available in different files, but rendering it all into one big file
would require some preprocessing.
2024-02-06 14:29:10 +01:00
Jackson 30ca6902c6 fix contrast for buttons and links in alert boxes
turns out, i broke the "Review patch" button link (.btn.btn-primary) in
the "this thread contains a patchset" info alert when trying to fix the
legacy OAuth link contrast.

this fixes both the "Review patch" button, and the legacy OAuth link,
and shouldn't break the contrast for any links and buttons in alert
boxes.

contrast for links on danger alert is fixed as well.

partially reverts commit 1dd2f363ce
2024-01-31 10:06:47 +01:00
Conrad Hoffmann 7fc2c6ca49 markdown: allow cell alignment in tables
Mistletoe supports Github's tables extension, including cell alignment
(see [1]). However, the sanitizer currently does not allow the align
attributes on the table cells, so the alignment never renders.

Add the align attribute to the list of allowed attributes for td and th
element, so that cell alignment works as expected.

[1] https://github.github.com/gfm/#example-199
2024-01-31 10:06:42 +01:00
Conrad Hoffmann b663dbe7cf validation: always escape error messages
The validation object's error messages are intended for display (i.e.
HTML rendering). To assert that no user-supplied HTML is ever rendered,
escape the error messages as they are passed in.

Thanks to Naglis Jonaitis for the report.
2024-01-24 13:29:55 +01:00
Conrad Hoffmann d7502248e0 graphql: escape error messages for validation
The GraphQL error messages can contain user-supplied input (such as text
input that was deemed invalid). However, the validation object's error
messages are intended for display (i.e. HTML rendering). To assert that
no user-supplied HTML is rendered, escape the GraphQL error messages as
they get copied to the validation object.

Thanks to Naglis Jonaitis for the report.
2024-01-24 13:25:17 +01:00
Conrad Hoffmann 37f5c27cbf markdown: fix name shadowing 2024-01-09 12:19:31 +01:00
Conrad Hoffmann aa38fcfc88 markdown: support disabling the sanitizer
Now that the sanitizer has become pretty strict, this will be needed for
the root wiki, where sanitization is not a concern, as the content comes
from the admin(s).
2024-01-09 11:31:53 +01:00
Julia DeMille b4cdcb0d60 Allow superscript and subscript in sanitized HTML.
This is useful for READMEs and the like -- the tags `sup` and `sub` are
not harmful, and allow for things like footnotes.

Signed-off-by: Julia DeMille <me@jdemille.com>
2024-01-09 10:20:08 +01:00
Väinö Mäkelä d293b4b434 flask: Set charset to "utf-8" instead of "utf8"
>From WHATWG Encoding specification section 4.2 "Names and labels" [1]:

  Authors must use the UTF-8 encoding and must use its (ASCII
  case-insensitive) "utf-8" label to identify it.

Although browsers must accept "utf8" as a charset, "utf-8" is the
standard spelling and should probably be used instead.

[1]: https://encoding.spec.whatwg.org/#names-and-labels
2024-01-09 10:18:35 +01:00
Conrad Hoffmann 9f8eda0c4a markdown: be more strict about sanitizing classes
Allowing arbitrary class attributes allows users to style content in
such way (be re-using global CSS classes) that they can escape the
intended target element, causing effects that can be considered suitable
for phishing.

Thanks to Ruben for the responsible disclosure.
2024-01-08 17:06:17 +01:00
Conrad Hoffmann 3f362e954c Remove dead code 2023-11-23 11:16:19 +01:00
Conrad Hoffmann c13da7cbf7 markdown: note about the escape_html_text wrapper
Signed-off-by: Conrad Hoffmann <ch@bitfehler.net>
2023-11-16 11:13:00 +01:00
Peter Sanchez 20a1381512 Updating escape html method name for newer versions of mistletoe
The `escape_html` method was renamed to `escape_html_text` in misletoe a
couple of versions ago. This is just updating for this change.

04bb2e65d9 (diff-d2c1aff85b502945367a9090fc11ed939c38e47fee41242114d6539a700010e1R202)
2023-11-16 11:06:52 +01:00
Drew DeVault 5dd53691c7 srht.database: set future=True on SQ create_engine
Fixes "AttributeError: 'Connection' object has no attribute 'commit'"
2023-10-30 09:21:07 +01:00
наб 4157c41ff0 markdown: don't auto-mailto:-link a@b in @a@b mastodon UID
This chases a similar report for github posted at
  https://101010.pl/@mcc@mastodon.social/110742090990556162
in that "@nabijaczleweli@101010.pl" is autolinked as
        "@<mailto:nabijaczleweli@101010.pl>"
which sucks for obvious reasons
(it's not actually a correct mail address,
 the actual purpose is muddied by the autolinking).

Instead, match against "@?<previous mail regex>", and eject addresses
that start with @s as raw text.
2023-10-04 10:48:25 +02:00
Jackson Chen 1dd2f363ce improve (button) links' contrast in alerts
fixes low contrast link for oauth legacy link in meta.sr.ht/oauth2 and
the confirmation link in user page for user admin.

retroactively applies the same CSS selector to other types of alerts,
hopefully this doesn't break something existing.
2023-10-04 10:48:21 +02:00
youkwhd cc4467fcf4 flask: set cookie sr.ht.unified-login.v1 as HTTP-Only
The cookie that is used to authenticate user could be stolen, this
happens because it is exposed to JavaScript:

    console.log(document.cookie)

Because it is exposed, someone could potentially steal the cookie and
use it as a bypass to get authenticated as a registered user, in the
event of a successful XSS exploitation.

References:
- <https://security.stackexchange.com/questions/260296/can-someone-clone-my-session-id-cookie-and-login-as-me>
- <https://flask.palletsprojects.com/en/2.3.x/api/#flask.Response.set_cookie>

Signed-off-by: youkwhd <lolywk@tutanota.com>
2023-10-04 10:47:38 +02:00
Conrad Hoffmann 9d194be927 Reduce unified login cookie size
By dropping some of the less likely-to-be-used items.
2023-09-21 10:50:10 +02:00
Drew DeVault cee1b399c4 oauth/interface: commit conn on user import 2023-08-28 10:18:05 +02:00
Drew DeVault 5e33dbc688 oauth/interface: update SQLAlchemy usage 2023-06-22 11:01:07 +02:00
Conrad Hoffmann 8cea995b8f Remove dependency on PGPy
It's mostly unused by now. The only small gotcha is that we stop signing
the error email (sent when catching otherwise unhandled exceptions).

Signed-off-by: Conrad Hoffmann <ch@bitfehler.net>
2023-06-01 12:34:04 +02:00
Drew DeVault 3e97507811 Upgrade to Alpine 3.17 2023-03-22 10:24:35 +01:00
Simon Ser ea11cd45d0 graphql: set GraphQLError.data
Even if errors occured, the server may return data. Store that
data in GraphQLError.data so that callers can easily access it.
2023-03-15 12:14:08 +01:00
Simon Ser b9e55a0a22 graphql: parse response JSON once on error 2023-03-15 12:14:07 +01:00
Simon Ser 599f3fe477 crypto: fix invalid JSON
Fixes the following TypeError:

    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
        response = self.full_dispatch_request()
      File "/usr/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/usr/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
        rv = self.dispatch_request()
      File "/usr/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
        return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
      File "/usr/lib/python3.9/site-packages/srht/oauth/decorator.py", line 83, in wrapper
        return _internal_auth(f, token[1], *args, **kwargs)
      File "/usr/lib/python3.9/site-packages/srht/oauth/decorator.py", line 23, in _internal_auth
        auth = verify_encrypted_authorization(auth)
      File "/usr/lib/python3.9/site-packages/srht/crypto.py", line 99, in verify_encrypted_authorization
        response=json.dumps({
    TypeError: unhashable type: 'dict'
2023-03-07 09:36:16 +01:00
Arsen Arsenović c5d90f431a flask: Enable the ``do'' Jinja2 extension 2023-02-22 09:25:48 +01:00
Adnan Maolood f8075fac4a srht/Makefile: Use minify cli to minify CSS
https://github.com/tdewolff/minify

minify is available in Alpine Linux package repositories. This also
removes a build-time dependency on node.
2023-02-22 09:22:37 +01:00
Umar Getagazov 83d4943c74 Make favicon visible in a light theme
The SVG version now switches colors with the browser's theme. An outline
is added to both SVG and PNG versions for browsers that do not support
`prefers-color-scheme` or SVG favicons. The PNG version now has an added
`sizes="any"` attribute to work around Chrome preferring it over SVG.
2023-02-14 09:21:58 +01:00
Simon Ser fb54daf26c markdown: fix TypeError on bleach 6
Fixes the following error:

    Traceback (most recent call last):
      File "/home/simon/src/meta.sr.ht/./metasrht-initdb", line 10, in <module>
        import metasrht.types
      File "/home/simon/src/meta.sr.ht/metasrht/types/__init__.py", line 1, in <module>
        from .user import *
      File "/home/simon/src/meta.sr.ht/metasrht/types/user.py", line 5, in <module>
        from srht.oauth import UserMixin, UserType
      File "/home/simon/src/core.sr.ht/srht/oauth/__init__.py", line 61, in <module>
        from srht.oauth.blueprint import oauth_blueprint
      File "/home/simon/src/core.sr.ht/srht/oauth/blueprint.py", line 6, in <module>
        from srht.flask import csrf_bypass
      File "/home/simon/src/core.sr.ht/srht/flask.py", line 11, in <module>
        from srht.markdown import markdown
      File "/home/simon/src/core.sr.ht/srht/markdown.py", line 175, in <module>
        tags=bleach.sanitizer.ALLOWED_TAGS + [
    TypeError: unsupported operand type(s) for +: 'frozenset' and 'list'
2023-02-14 09:21:55 +01:00
Conrad Hoffmann 8652a9ef70 Don't inline favicon, offer SVG version
Currently, the favicon is served as inline data with every page. This
commit makes it an external resource instead, so it can benefit from
caching. In addition, an SVG version is added, which is not supported by
all browsers [1], but is roughly one tenth of the size. It is the one
displayed in the header on every page, only in white.

[1]: https://caniuse.com/link-icon-svg
2023-01-26 10:14:02 +01:00
Adnan Maolood 27509d25bf srht/oauth: Use canonical user IDs
When adding users to the database, use the canonical user ID from
meta.sr.ht.
2022-10-25 10:05:43 +02:00
Simon Ser 030a0cd789 graphql/client: add oauth2_token authentication
This executes a GraphQL operation with the specified OAuth 2.0
token used for authentication.

This will be useful to implement OAuth 2.0 token introspection.
2022-09-29 10:48:00 +02:00
Simon Ser de41276798 flask: add cross_origin
A Flask decorator to enable CORS.

This will be useful to allow browser-based clients to perform
HTTP requests on some endpoints, e.g. to allow gamja to use the
OAuth 2.0 endpoints.
2022-09-22 10:51:11 +02:00