Part-DB / Part-DB-server

Part-DB is an Open source inventory management system for your electronic components
https://docs.part-db.de/
GNU Affero General Public License v3.0
782 stars 88 forks source link

Footprint autocomplete will suggest HTML elements #587

Closed Gnarflord closed 2 months ago

Gnarflord commented 3 months ago

Describe the bug When I begin typing in the field for my KiCad footprint I will get HTML elements as suggestions: image (Resistor_R:R_1206_3216Metric was added manually by me, I don't get any auto-completes from the default library)

Now If I empty the field I can see the whole HTML document being parsed. This is a fun way of debugging I've never encountered before :) image

Untitled

Now that's basically my Apache server telling me that there's a 404 error and the URL does not exist. If I look into the Apache log I see:

[06/Apr/2024:11:00:19 +0200] "GET /kicad/footprints.txt HTTP/1.1" 404 1137

Aha! I'm hosting under a subpath like https://myurl.com/partdb but the footprint lookup searches under https://myurl.com without the subpath. My Apache config for the reverse proxy looks like this:

<Location "/partdb">
        ProxyPreserveHost On
        ProxyPass "http://localhost:8081"
        ProxyPassReverse "http://localhost:8081"
        RequestHeader set X-Forwarded-Prefix "/partdb"
</Location>

Maybe I've set something up the wrong way but X-Forwarded-Prefix is definitely working as the page breaks completely if it's missing. But somehow X-Forwarded-Prefix is ignored for this particularly footprint lookup.

I have also set DEFAULT_URI to https://myurl.com/partdb/ but that doesn't seem to have any impact.

Server Side

Desktop (please complete the following information):

Gnarflord commented 3 months ago

I have also noticed that the URLs for API access are not correct, which seems to be a related issue:

Untitled

What I expect

Part-DB API: https://myurl.com/partdb/api
KiCad API root URL: https://myurl.com/partdb/en/kicad-api/

What I got

Part-DB API: http://myurl.com/partdb/api
KiCad API root URL: http://myurl.com/en/kicad-api/

So the issues are:

jbtronics commented 2 months ago

Have you set the correct TRUSTED_PROXIES env for Part-DB?

Gnarflord commented 2 months ago

My env contains: TRUSTED_PROXIES=127.0.0.1,REMOTE_ADDR As to my understanding that basically allows connections from any address, right?

I can also manually access https://myurl.com/partdb/kicad/footprints.txt and see the correct file in my browser. The issue only arises because the interface wants to look up https://myurl.com/kicad/footprints.txt instead

jbtronics commented 2 months ago

This is now fixed