2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 03:26:45 +00:00

[CUI] Fix rendering issues for barcodes (#8286) (#8288)

- Prevent barcode data from being "escaped"
- Run through bleach to brevent malicious data injection

(cherry picked from commit b1d9a2392884edc6135a247022d74792cb993b78)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
github-actions[bot] 2024-10-15 17:28:40 +11:00 committed by GitHub
parent 3659bbe389
commit cebad3d142
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 34 additions and 8 deletions

View File

@ -3,6 +3,7 @@
{% load static %}
{% load i18n %}
{% load generic %}
{% load barcode %}
{% load inventree_extras %}
{% block page_title %}
@ -277,7 +278,7 @@ src="{% static 'img/blank_image.png' %}"
$('#show-qr-code').click(function() {
showQRDialog(
'{% trans "Build Order QR Code" escape %}',
'{{ build.barcode }}'
`{% clean_barcode build.barcode %}`
);
});

View File

@ -1,6 +1,7 @@
{% extends "page_base.html" %}
{% load static %}
{% load i18n %}
{% load barcode %}
{% load inventree_extras %}
{% block page_title %}
@ -303,7 +304,7 @@ onPanelLoad('supplier-part-notes', function() {
$("#show-qr-code").click(function() {
showQRDialog(
'{% trans "Supplier Part QR Code" escape %}',
'{{ part.barcode }}'
`{% clean_barcode part.barcode %}`
);
});

View File

@ -2,6 +2,7 @@
{% load i18n %}
{% load static %}
{% load barcode %}
{% load inventree_extras %}
{% load generic %}
@ -312,7 +313,7 @@ $("#export-order").click(function() {
$('#show-qr-code').click(function() {
showQRDialog(
'{% trans "Purchase Order QR Code" escape %}',
'{{ order.barcode }}'
`{% clean_barcode order.barcode %}`
);
});

View File

@ -2,6 +2,7 @@
{% load i18n %}
{% load static %}
{% load barcode %}
{% load inventree_extras %}
{% load generic %}
@ -257,7 +258,7 @@ $('#print-order-report').click(function() {
$('#show-qr-code').click(function() {
showQRDialog(
'{% trans "Return Order QR Code" escape %}',
'{{ order.barcode }}'
`{% clean_barcode order.barcode %}`
);
});

View File

@ -2,6 +2,7 @@
{% load i18n %}
{% load static %}
{% load barcode %}
{% load inventree_extras %}
{% load generic %}
@ -319,7 +320,7 @@ $('#print-order-report').click(function() {
$('#show-qr-code').click(function() {
showQRDialog(
'{% trans "Sales Order QR Code" escape %}',
'{{ order.barcode }}'
`{% clean_barcode order.barcode %}`
);
});

View File

@ -2,6 +2,7 @@
{% load static %}
{% load i18n %}
{% load barcode %}
{% load inventree_extras %}
{% block sidebar %}
@ -451,7 +452,7 @@
$("#show-qr-code").click(function() {
showQRDialog(
'{% trans "Part QR Code" escape %}',
'{{ part.barcode|safe }}',
`{% clean_barcode part.barcode %}`
);
});

View File

@ -1,6 +1,7 @@
"""Template tags for rendering various barcodes."""
from django import template
from django.utils.safestring import mark_safe
import barcode as python_barcode
import qrcode.constants as ECL
@ -26,6 +27,23 @@ def image_data(img, fmt='PNG'):
return report.helpers.encode_image_base64(img, fmt)
@register.simple_tag()
def clean_barcode(data):
"""Return a 'cleaned' string for encoding into a barcode / qrcode.
- This function runs the data through bleach, and removes any malicious HTML content.
- Used to render raw barcode data into the rendered HTML templates
"""
from InvenTree.helpers import strip_html_tags
cleaned_date = strip_html_tags(data)
# Remove back-tick character (prevent injection)
cleaned_date = cleaned_date.replace('`', '')
return mark_safe(cleaned_date)
@register.simple_tag()
def qrcode(data, **kwargs):
"""Return a byte-encoded QR code image.

View File

@ -3,6 +3,7 @@
{% load plugin_extras %}
{% load inventree_extras %}
{% load generic %}
{% load barcode %}
{% load i18n %}
{% load l10n %}
@ -534,7 +535,7 @@ $('#stock-edit-status').click(function () {
$("#show-qr-code").click(function() {
showQRDialog(
'{% trans "Stock Item QR Code" escape %}',
'{{ item.barcode }}',
`{% clean_barcode item.barcode %}`
);
});

View File

@ -1,5 +1,6 @@
{% extends "stock/stock_app_base.html" %}
{% load static %}
{% load barcode %}
{% load inventree_extras %}
{% load plugin_extras %}
{% load i18n %}
@ -391,7 +392,7 @@
$('#show-qr-code').click(function() {
showQRDialog(
'{% trans "Stock Location QR Code" escape %}',
'{{ location.barcode }}'
`{% clean_barcode location.barcode %}`
);
});