Home > Blockchain >  How to match any url contains a certain string (such as .jsp) in Django?
How to match any url contains a certain string (such as .jsp) in Django?

Time:07-03

I'd like to soft reject any path that contains a string, such as .jsp in the Django 3. Here is my url.py:

from django.urls import re_path
from django.views.generic import TemplateView

re_path(
    r"^.*\.jsp\??.*$",
    TemplateView.as_view(template_name="404.txt", content_type="text/plain"),
),

The above path pattern can match an ordinary string like /whatever.jsp, but cannot match the following probing string. How to improve my re_path pattern to match this? Thanks!

/content/..;/crx/packmgr/list.jsp;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
;
a.css?_dc=1615863080856&_charset_=utf-8&includeVersions=true

CodePudding user response:

what about this regex r"[^\.](.*)\.jsp(.*)"

  • Related