Commit graph

918 commits

Author SHA1 Message Date
Théo Lebrun
1853abe7f9 README: fix docker image instructions
Two issues are fixed:

 - Initial `docker build` instructions fail because the Dockerfile path
   is wrong (elixir/Dockerfile versus elixir/docker/Dockerfile).

 - Indexing instructions are wrong because they do not use the
   virtualenv Python. It contains the installed packages, which we need
   for indexing. Issue appears as:

      ModuleNotFoundError: No module named 'bsddb3' (edited)

We also remove some common Docker knowledge (why we might want the
database to be coming from a mounted volume, rather than stored inside
the container).

Finally, we fix line widths but splitting commands into multiple lines.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-10-01 16:03:24 +02:00
Franciszek Stachura
426fff2dc5 web: Fix identifier unquoting
to make DT compatibles work again...
2024-09-30 14:14:13 +02:00
Théo Lebrun
4aac8fc8dc web: error page: make Github issue TODO message more straight forward
We reword the TODO message. We put two newlines before and after the
triple dashes to avoid Markdown title formatting.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-09-30 12:22:42 +02:00
Franciszek Stachura
46254c4a90 web: Add error details for bug reports 2024-09-30 12:00:53 +02:00
Franciszek Stachura
76d13c9193 web: Make GET /ident redirect to /source
Now making a GET to /project/version/ident will redirect to
/project/version/source.
Refreshing a page after making a request for an empty identifier won't
show 405 Method Not Allowed anymore.
2024-09-30 12:00:53 +02:00
Franciszek Stachura
5aca2d51e5 web: Improve error page
Add some useful links, including a link to a pre-filled bug report form
2024-09-30 12:00:53 +02:00
Franciszek Stachura
e4b72b22ad web: Add breadcrubs to source 404 2024-09-30 12:00:53 +02:00
Franciszek Stachura
5b11f7b201 web: Add more context to error handling 2024-09-30 12:00:53 +02:00
Franciszek Stachura
36dd519b34 web: Move path parameter validation to resources 2024-09-30 12:00:53 +02:00
Théo Lebrun
e25b3d7c4b static: add /robots.txt
This is NOT being served by Elixir backend. The HTTP server in front
must serve it. Commit robots.txt to store the file somewhere.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-09-27 18:19:11 +02:00
Théo Lebrun
60699c4155 web: templates/layout: add favicon <link> tag
For some reason, browsers do not automatically pick up the hosted
favicon.ico available on staging server. Add an explicit line to
describe the availability of /favicon.ico.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-09-27 18:17:00 +02:00
Théo Lebrun
007248e61f web: static/img: commit favicon.ico
favicon.ico being served is not dependent on Elixir's configuration, but
on the front-facing server. Its config must be updated to serve the
favicon; this is why favicon.ico used to not be commited into the
repo.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-09-27 17:48:34 +02:00
Théo Lebrun
2eb21c82f6 web: templates/topbar: mark searchbar as required
Mark the searchbar as a required input. This avoids <Enter> on an empty
searchbar to send a "POST /$PROJECT/$VERSION/ident" with empty value,
which triggers an error.

This is made more frequent by the fact that the searchbar is
automatically focused. It also avoids implementing logic on the backend
to redirect to the previous page if an empty search was submitted.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-09-27 17:27:25 +02:00
Franciszek Stachura
4c0f2cf42b web: increment ?v= following script refactoring 2024-09-26 13:05:00 +02:00
Franciszek Stachura
e8f8a2e7b4 js: Switch to strict mode in script.js
The script should be compatible with strict mode, and strict mode
prevents some annoying bugs. The most important, it prevents assigning
to an undeclared variable.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
2024-09-26 13:05:00 +02:00
Franciszek Stachura
ef1b83ad75 js: Move minor fixes into functions
Move the following to new functions:
* anchor offset handler
* 301 fix
* autoscrolling prevention

Hookup onload handler with addEventListener.

About autoscrolling prevention:

I'm not sure if this is still relevant. I'm unable to trigger this
behavior. I think it could be related to a some kind of a Chrome bug.

https://forum.jquery.com/portal/en/community/topic/chrome-bug-or-how-do-i-prevent-a-form-field-to-scroll-the-container-when-focused
https://stackoverflow.com/questions/49318282/how-to-prevent-autoscroll-to-focused-input
2024-09-26 13:05:00 +02:00
Franciszek Stachura
2f7b56a4d8 js: Refactor go-to-top handler
href # doesn't work... probably because the wrapper
2024-09-26 13:05:00 +02:00
Franciszek Stachura
61ca8e19f2 js: Refactor sidebar hamburger button script
Move hamburger menu handlers to a new setup function, called from
onload.
2024-09-26 13:04:57 +02:00
Franciszek Stachura
e333b33364 js: Refactor versions tree expand/collapse script
Move versions tree handlers to a new setup function, called from
onload.
2024-09-26 12:48:34 +02:00
Franciszek Stachura
b9817c412b js: Refactor tags filter
Move tag filter setup into a new function, refactor related functions
to avoid global variables. Set up tags filter from onload handler.
2024-09-26 12:48:34 +02:00
Franciszek Stachura
f3d43c380b web: Fix sidebar state if page loaded as mobile
Fixes the following bug:

1. Make sure show-menu == true
2. Open page in mobile mode
3. Reisze to widescreen

Sidebar will be hidden until page is reloaded.
2024-09-20 15:24:59 +02:00
Franciszek Stachura
32141d8e96 web: Fix mobile sidebar close with backdrop click 2024-09-20 15:22:47 +02:00
Théo Lebrun
1aa74c4dc9 web: templates/layout.html: increment ?v= following range anchors fix
As usual, we must increment those version numbers when changes are made
to style.css and/or script.js. That purges the production cache.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-09-20 14:35:17 +02:00
Franciszek Stachura
c8d088834d web: Make mobile sidebar state separate
...from desktop sidebar state.

Fixes #331
2024-09-20 14:33:01 +02:00
Franciszek Stachura
9a27c7ae20 autocomplete: Submit form on item selection 2024-09-13 11:22:28 +02:00
Théo Lebrun
713401cf95 web: templates/layout.html: increment ?v= following range anchors fix
As usual, we must increment those version numbers when changes are made
to style.css and/or script.js. That purges the production cache.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-09-11 15:45:36 +02:00
Franciszek Stachura
b2c3ab73e9 web: Fix highlighting when second select is before first 2024-09-11 15:40:57 +02:00
Théo Lebrun
8059650f1e web: templates/layout.html: increment ?v= following range anchors
As usual, we must increment those version numbers when changes are made
to style.css and/or script.js. That purges the production cache.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-09-11 11:49:45 +02:00
Franciszek Stachura
30933fea6a web: Highlight whole lines of code 2024-09-11 11:48:27 +02:00
Franciszek Stachura
3b4bcd852a web: Add javascript based range links
Click line anchor and another line anchor holding shift to
make a link to a range.
2024-09-11 11:48:27 +02:00
Théo Lebrun
378dcf7e49 web: templates/layout.html: increment ?v= following sidebar changes
As usual, we must increment those version numbers when changes are made
to style.css and/or script.js. That purges the production cache.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-09-11 11:36:32 +02:00
Théo Lebrun
0b65c2c459 web: refactor showSidebar computation
The local storage API returns strings and has no way to set a default
value in case no value exists. We must therefore check for the "true"
string or the null value.

Let's extract it from the if boolean expression. We go from:

    if (isWidescreen && (showSidebar === "true" || showSidebar === null))

To:

    if (isWidescreen && showSidebar)

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-09-11 11:20:17 +02:00
Franciszek Stachura
0e9ff63c15 web: Save sidebar state in local storage 2024-09-11 11:13:16 +02:00
Franciszek Stachura
ec37680f04 web: Add ability to hide sidebar on desktop layout
The sidebar is hidden by default
2024-09-11 11:13:13 +02:00
Franciszek Stachura
0fed56ea25 web: Move sidebar above content
...in layout to make it load before (potentially) long source or list
of identifiers.
Reduces chances of layout shifts during load of mentioned pages.
2024-09-11 11:13:10 +02:00
Franciszek Stachura
b5d4c1ae04 web: Explicitly close Query after finishing request
API closes Query and isn't known to leak memory.
BsdDB seems to have automatic destructors, but maybe there are
some caveats.
The documentation does not say that objects have to be closed
explicitly... But it probably won't hurt. And this is the only
hint I found when trying to debug the leak so far.

https://hg.jcea.es/pybsddb/file/6.2.9/Modules/_bsddb.c#l8943
https://pybsddb.sourceforge.net/bsddb3.html
2024-09-10 10:38:52 +02:00
Franciszek Stachura
f5c7c3c1ec templates: Remove png version of logo
Backwards compatibility for browsers without svg support (in this
version) causes the logo to unnecessarily flicker on navigation.

According to caniuse.com SVG in img elements is supported in browsers
used by 97.85% of users. https://caniuse.com/svg-img
Firefox introduced support in 2011, Chrome in 2013, Safari in 2015.
2024-09-09 16:33:12 +02:00
Franciszek Stachura
8c5e12fffd Add support for 'raw' parameter for source files
This parameter makes the server return a response with raw file
contents and headers that cause the browser to show a 'save as' dialog.

Regarding Content-Security-Policy:

https://www.w3.org/TR/CSP2/#sandbox-usage

> For example, a message board or email system might provide downloads of
> arbitrary attachments provided by other users. Attacks that rely on tricking
> a client into rendering one of these attachments could be mitigated by
> requesting that resources only be rendered in a very restrictive sandbox.
> Sending the sandbox directive with an empty value establishes such an
> environment:
>
> Content-Security-Policy: sandbox

https://www.w3.org/TR/CSP2/#directive-default-src

> Given this behavior, one good way of building a policy for a site would be to
> begin with a default-src of 'none', and to build up a policy from there that
> contains only those resource types which are actually in use for the page
> you’d like to protect. If you don’t use webfonts, for instance, there’s no
> reason to specify a source list for font-src; specifying only those resource
> types a page uses ensures that the possible attack surface for that page
> remains as small as possible.

https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html#defense-in-depth

> A strong CSP provides an effective second layer of protection against various
> types of vulnerabilities, especially XSS. Although CSP doesn't prevent web
> applications from containing vulnerabilities, it can make those
> vulnerabilities significantly more difficult for an attacker to exploit.

The idea is to prevent the browser from loading any external resources, if it
turned out it's possible to trick it into interpreting a file as HTML.
2024-09-05 14:12:53 +02:00
Théo Lebrun
4058a4b4f0 web: change versions cache duration from 30m to 2m
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-08-30 20:59:08 +02:00
Franciszek Stachura
d946818e81 web: Add versions cache 2024-08-30 20:47:19 +02:00
Franciszek Stachura
00a160a154 web: Make Jinja environment global for app
This allows Jinja to cache templates between requests.
2024-08-30 16:39:32 +02:00
Théo Lebrun
ab9d776397 frontend: header: fix Bootlin logo paths and commit logo png+svg
Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
2024-08-27 15:50:08 +02:00
Franciszek Stachura
6010470f3d web.py: Add error serializer, raise HTTP errors 2024-08-27 11:33:19 +02:00
Franciszek Stachura
214f606e07 README: update with information about WSGI version of Elixir
* Add changelog
2024-08-27 11:33:19 +02:00
Franciszek Stachura
287569de2f autocomplete: Validate query parameters 2024-08-27 11:33:19 +02:00
Franciszek Stachura
998f3a3da0 api, web.py: Move validators, validate API URLs 2024-08-27 11:33:19 +02:00
Franciszek Stachura
6e01f3b023 Dockerfile: update to support WSGI Elixir
* Build bsddb in a separate stage to avoid using system packages in venv
* Update Docker Apache config to support WSGI
2024-08-27 11:33:19 +02:00
Franciszek Stachura
9e18f26aeb Restructure Elixir to avoid Python path hacks
* Move static files from http to a new directory
2024-08-27 11:33:18 +02:00
Franciszek Stachura
584c98686d Move get_query to query.py
Refactor api and autocomplete to use it and properly handle errors
related to invalid project names.
2024-08-27 11:32:19 +02:00
Franciszek Stachura
1ace9f746f api: Move to main application 2024-08-27 11:32:19 +02:00