code
stringlengths
14
2.05k
label
int64
0
1
programming_language
stringclasses
7 values
cwe_id
stringlengths
6
14
cwe_name
stringlengths
5
98
description
stringlengths
36
379
url
stringlengths
36
48
label_name
stringclasses
2 values
def serve_file_unauthed_from_token( request: HttpRequest, token: str, filename: str ) -> HttpResponseBase: path_id = get_file_path_id_from_token(token) if path_id is None: raise JsonableError(_("Invalid token")) if path_id.split("/")[-1] != filename: raise JsonableError(_("Invalid filena...
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def get_file_path_id_from_token(token: str) -> Optional[str]: signer = TimestampSigner(salt=USER_UPLOADS_ACCESS_TOKEN_SALT) try: signed_data = base64.b16decode(token).decode() path_id = signer.unsign(signed_data, max_age=timedelta(seconds=60)) except (BadSignature, binascii.Error): r...
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def serve_local(request: HttpRequest, path_id: str, download: bool = False) -> HttpResponseBase: assert settings.LOCAL_FILES_DIR is not None local_path = os.path.join(settings.LOCAL_FILES_DIR, path_id) assert_is_local_storage_path("files", local_path) if not os.path.isfile(local_path): return Ht...
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def serve_local_avatar_unauthed(request: HttpRequest, path: str) -> HttpResponseBase: """Serves avatar images off disk, via nginx (or directly in dev), with no auth. This is done unauthed because these need to be accessed from HTML emails, where the client does not have any auth. We rely on the URL be...
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def serve_file( request: HttpRequest, maybe_user_profile: Union[UserProfile, AnonymousUser], realm_id_str: str, filename: str, url_only: bool = False, download: bool = False, ) -> HttpResponseBase: path_id = f"{realm_id_str}/{filename}" realm = get_valid_realm_from_request(request) i...
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def generate_unauthed_file_access_url(path_id: str) -> str: signed_data = TimestampSigner(salt=USER_UPLOADS_ACCESS_TOKEN_SALT).sign(path_id) token = base64.b16encode(signed_data.encode()).decode() filename = path_id.split("/")[-1] return reverse("file_unauthed_from_token", args=[token, filename])
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def serve_s3(request: HttpRequest, path_id: str, download: bool = False) -> HttpResponse: url = get_signed_upload_url(path_id) assert url.startswith("https://") if settings.DEVELOPMENT: # In development, we do not have the nginx server to offload # the response to; serve a redirect to the s...
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def get_signed_upload_url(path: str, force_download: bool = False) -> str: client = boto3.client( "s3", aws_access_key_id=settings.S3_KEY, aws_secret_access_key=settings.S3_SECRET_KEY, region_name=settings.S3_REGION, endpoint_url=settings.S3_ENDPOINT_URL, ) params = {...
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def serve_file_unauthed_from_token( request: HttpRequest, token: str, filename: str ) -> HttpResponseBase: path_id = get_file_path_id_from_token(token) if path_id is None: raise JsonableError(_("Invalid token")) if path_id.split("/")[-1] != filename: raise JsonableError(_("Invalid filena...
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def serve_local( request: HttpRequest, path_id: str, force_download: bool = False ) -> HttpResponseBase: assert settings.LOCAL_FILES_DIR is not None local_path = os.path.join(settings.LOCAL_FILES_DIR, path_id) assert_is_local_storage_path("files", local_path) if not os.path.isfile(local_path): ...
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def serve_s3(request: HttpRequest, path_id: str, force_download: bool = False) -> HttpResponse: url = get_signed_upload_url(path_id, force_download=force_download) assert url.startswith("https://") if settings.DEVELOPMENT: # In development, we do not have the nginx server to offload # the r...
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def serve_file_download_backend( request: HttpRequest, user_profile: UserProfile, realm_id_str: str, filename: str ) -> HttpResponseBase: return serve_file( request, user_profile, realm_id_str, filename, url_only=False, force_download=True )
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def serve_file( request: HttpRequest, maybe_user_profile: Union[UserProfile, AnonymousUser], realm_id_str: str, filename: str, url_only: bool = False, force_download: bool = False, ) -> HttpResponseBase: path_id = f"{realm_id_str}/{filename}" realm = get_valid_realm_from_request(request)...
1
Python
CWE-436
Interpretation Conflict
Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state.
https://cwe.mitre.org/data/definitions/436.html
safe
def create(self, request, *args, **kwargs): if User.objects.filter(is_superuser=True).exists() and not request.user.is_superuser: return Response(status=status.HTTP_401_UNAUTHORIZED) return super(UserViewSet, self).create(request, *args, **kwargs)
1
Python
NVD-CWE-Other
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
https://nvd.nist.gov/vuln/categories
safe
def get(self, request, format=None): try: return Response({"isFirstTimeSetup": not User.objects.filter(is_superuser=True).exists()}) except Exception as e: logger.exception(str(e)) return Response({"message": str(e)})
1
Python
NVD-CWE-Other
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
https://nvd.nist.gov/vuln/categories
safe
def get_permissions(self): if self.action == "create": self.permission_classes = [ IsRegistrationAllowed | FirstTimeSetupPermission | IsAdminUser ] if self.request.method == "POST": self.permission_classes = (AllowAny,) return super(UserVie...
1
Python
NVD-CWE-Other
Other
NVD is only using a subset of CWE for mapping instead of the entire CWE, and the weakness type is not covered by that subset.
https://nvd.nist.gov/vuln/categories
safe
async def form(self) -> FormMultiDict: """Retrieve form data from the request. If the request is either a 'multipart/form-data' or an 'application/x-www-form- urlencoded', return a FormMultiDict instance populated with the values sent in the request, otherwise, an empty instance. Re...
1
Python
CWE-770
Allocation of Resources Without Limits or Throttling
The product allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on the size or number of resources that can be allocated, in violation of the intended security policy for that actor.
https://cwe.mitre.org/data/definitions/770.html
safe
async def extract_multipart( connection: "Request[Any, Any]", ) -> Any: multipart_form_part_limit = ( body_kwarg_multipart_form_part_limit if body_kwarg_multipart_form_part_limit is not None else connection.app.multipart_form_part_limit ) conne...
1
Python
CWE-770
Allocation of Resources Without Limits or Throttling
The product allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on the size or number of resources that can be allocated, in violation of the intended security policy for that actor.
https://cwe.mitre.org/data/definitions/770.html
safe
def create_multipart_extractor( signature_field: "SignatureField", is_data_optional: bool ) -> Callable[["ASGIConnection[Any, Any, Any]"], Coroutine[Any, Any, Any]]: """Create a multipart form-data extractor. Args: signature_field: A SignatureField instance. is_data_optional: Boolean dictat...
1
Python
CWE-770
Allocation of Resources Without Limits or Throttling
The product allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on the size or number of resources that can be allocated, in violation of the intended security policy for that actor.
https://cwe.mitre.org/data/definitions/770.html
safe
def parse_body(body: bytes, boundary: bytes, multipart_form_part_limit: int) -> List[bytes]: """Split the body using the boundary and validate the number of form parts is within the allowed limit. :param body: The form body. :param boundary: The boundary used to separate form components. :param...
1
Python
CWE-770
Allocation of Resources Without Limits or Throttling
The product allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on the size or number of resources that can be allocated, in violation of the intended security policy for that actor.
https://cwe.mitre.org/data/definitions/770.html
safe
def app_config_object() -> AppConfig: return AppConfig( after_exception=[], after_request=None, after_response=None, after_shutdown=[], after_startup=[], allowed_hosts=[], before_request=None, before_send=[], before_shutdown=[], before_...
1
Python
CWE-770
Allocation of Resources Without Limits or Throttling
The product allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on the size or number of resources that can be allocated, in violation of the intended security policy for that actor.
https://cwe.mitre.org/data/definitions/770.html
safe
def test_multipart_form_part_limit(limit: int) -> None: @post("/") async def hello_world(data: List[UploadFile] = Body(media_type=RequestEncodingType.MULTI_PART)) -> None: assert len(data) == limit with create_test_client(route_handlers=[hello_world], multipart_form_part_limit=limit) as client: ...
1
Python
CWE-770
Allocation of Resources Without Limits or Throttling
The product allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on the size or number of resources that can be allocated, in violation of the intended security policy for that actor.
https://cwe.mitre.org/data/definitions/770.html
safe
async def hello_world( data: List[UploadFile] = Body(media_type=RequestEncodingType.MULTI_PART, multipart_form_part_limit=route_limit) ) -> None: assert len(data) == route_limit
1
Python
CWE-770
Allocation of Resources Without Limits or Throttling
The product allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on the size or number of resources that can be allocated, in violation of the intended security policy for that actor.
https://cwe.mitre.org/data/definitions/770.html
safe
def test_multipart_form_part_limit_body_param_precedence() -> None: app_limit = 100 route_limit = 10 @post("/") async def hello_world( data: List[UploadFile] = Body(media_type=RequestEncodingType.MULTI_PART, multipart_form_part_limit=route_limit) ) -> None: assert len(data) == route...
1
Python
CWE-770
Allocation of Resources Without Limits or Throttling
The product allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on the size or number of resources that can be allocated, in violation of the intended security policy for that actor.
https://cwe.mitre.org/data/definitions/770.html
safe
async def hello_world(data: List[UploadFile] = Body(media_type=RequestEncodingType.MULTI_PART)) -> None: assert len(data) == limit
1
Python
CWE-770
Allocation of Resources Without Limits or Throttling
The product allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on the size or number of resources that can be allocated, in violation of the intended security policy for that actor.
https://cwe.mitre.org/data/definitions/770.html
safe
def test_safe_render(self): """Assert that safe Jinja rendering still works.""" site = Site.objects.filter(region__isnull=False).first() template_code = "{{ obj.region.name }}" try: value = render_jinja2(template_code=template_code, context={"obj": site}) except S...
1
Python
NVD-CWE-noinfo
null
null
null
safe
def test_sandboxed_render(self): """Assert that Jinja template rendering is sandboxed.""" template_code = "{{ ''.__class__.__name__ }}" with self.assertRaises(SecurityError): render_jinja2(template_code=template_code, context={})
1
Python
NVD-CWE-noinfo
null
null
null
safe
def nested_serializer_factory(relation_info, nested_depth): """ Return a NestedSerializer representation of a serializer field. This method should only be called in build_nested_field() in which relation_info and nested_depth are already given. """ nested_serializer_name = f"Nested{nested_depth}...
1
Python
CWE-312
Cleartext Storage of Sensitive Information
The product stores sensitive information in cleartext within a resource that might be accessible to another control sphere.
https://cwe.mitre.org/data/definitions/312.html
safe
def assert_no_verboten_content(self, response): """ Check an API response for content that should not be exposed in the API. If a specific API has a false failure here (maybe it has security-related strings as model flags or something?), its test case should overload self.VERBOTEN_S...
1
Python
CWE-312
Cleartext Storage of Sensitive Information
The product stores sensitive information in cleartext within a resource that might be accessible to another control sphere.
https://cwe.mitre.org/data/definitions/312.html
safe
def test_list_objects_depth_1(self): """ GET a list of objects using the "?depth=1" parameter. """ depth_fields = self.get_depth_fields() self.add_permissions(f"{self.model._meta.app_label}.view_{self.model._meta.model_name}") url = f"{self...
1
Python
CWE-312
Cleartext Storage of Sensitive Information
The product stores sensitive information in cleartext within a resource that might be accessible to another control sphere.
https://cwe.mitre.org/data/definitions/312.html
safe
def test_list_objects(self): """ GET a list of objects as an authenticated user with permission to view the objects. """ self.assertGreaterEqual( self._get_queryset().count(), 3, f"Test requires the creation of at le...
1
Python
CWE-312
Cleartext Storage of Sensitive Information
The product stores sensitive information in cleartext within a resource that might be accessible to another control sphere.
https://cwe.mitre.org/data/definitions/312.html
safe
def render(self, record, bound_column, value): # pylint: disable=arguments-differ if value: name = bound_column.name css_class = getattr(record, f"get_{name}_class")() label = getattr(record, f"get_{name}_display")() return format_html('<span class="label lab...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def render(self, value): return format_html('<span class="label color-block" style="background-color: #{}">&nbsp;</span>', value)
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def render(self, record, value): # pylint: disable=arguments-differ if value: url = reverse(self.viewname, kwargs=self.view_kwargs) if self.url_params: url += "?" + "&".join([f"{k}={getattr(record, v)}" for k, v in self.url_params.items()]) return format_...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def header(self): return mark_safe('<input type="checkbox" class="toggle" title="Toggle all" />') # noqa: S308
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def add_html_id(element_str, id_str): """Add an HTML `id="..."` attribute to the given HTML element string. Args: element_str (str): String describing an HTML element. id_str (str): String to add as the `id` attribute of the element_str. Returns: (str): HTML string with added `id`....
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def render_boolean(value): """Render HTML from a computed boolean value. Args: value (any): Input value, can be any variable. A truthy value (for example non-empty string / True / non-zero number) is considered True. A falsey value other than None (for example "" or 0 or False) ...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def render_markdown(value): """ Render text as Markdown Example: {{ text | render_markdown }} """ # Strip HTML tags value = strip_tags(value) # Sanitize Markdown links schemes = "|".join(settings.ALLOWED_URL_SCHEMES) pattern = rf"\[(.+)\]\((?!({schemes})).*:(.+)\)" valu...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def placeholder(value): """Render a muted placeholder if value is falsey, else render the value. Args: value (any): Input value, can be any variable. Returns: (str): Placeholder in HTML, or the string representation of the value. Example: >>> placeholder("") '<span cla...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def render_jinja2(template_code, context): """ Render a Jinja2 template with the provided context. Return the rendered content. """ rendering_engine = engines["jinja"] template = rendering_engine.from_string(template_code) # For reasons unknown to me, django-jinja2 `template.render()` implicitly...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def successful_post(self, request, obj, created, logger): """Callback after the form is successfully saved but before redirecting the user.""" verb = "Created" if created else "Modified" msg = f"{verb} {self.queryset.model._meta.verbose_name}" logger.info(f"{msg} {obj} (PK: {obj.pk})...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def filter_queryset(self, queryset): """ Filter a query with request querystrings. """ if self.filterset_class is not None: self.filter_params = self.get_filter_params(self.request) self.filterset = self.filterset_class(self.filter_params, queryset) ...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def _process_create_or_update_form(self, form): """ Helper method to create or update an object after the form is validated successfully. """ request = self.request queryset = self.get_queryset() with transaction.atomic(): object_created = not form.instanc...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def handle_protectederror(obj_list, request, e): """ Generate a user-friendly error message in response to a ProtectedError exception. """ protected_objects = list(e.protected_objects) protected_count = len(protected_objects) if len(protected_objects) <= 50 else "More than 50" err_message = form...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def post(self, request, pk): virtual_chassis = get_object_or_404(self.queryset, pk=pk) member_select_form = forms.VCMemberSelectForm(request.POST) if member_select_form.is_valid(): device = member_select_form.cleaned_data["device"] device.virtual_chassis = virtual_c...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def render_description(self, record): if record.description: return render_markdown(record.description) return self.default
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def computed_fields(context, obj, advanced_ui=None): """ Render all applicable links for the given object. This can also check whether the advanced_ui attribute is True or False for UI display purposes. """ fields = obj.get_computed_fields(label_as_key=True, advanced_ui=advanced_ui) if not compu...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def _get_registered_content(obj, method, template_context, return_html=True): """ Given an object and a TemplateExtension method name and the template context, return all the registered content for the object's model. """ context = { "object": obj, "request": template_context["reques...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_custom_field_table_render(self): queryset = Location.objects.filter(name=self.location.name) location_table = LocationTable(queryset) custom_column_expected = { "text_field": "bar", "number_field": "456", "boolean_field": '<span class="text-succe...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_view_object_with_computed_field(self): """Ensure that the computed field template is rendered.""" response = self.client.get(self.location_type.get_absolute_url(), follow=True) self.assertEqual(response.status_code, 200) content = extract_page_body(response.content.decode(re...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_view_object_with_unsafe_custom_link_name(self): """Ensure that custom links can't be used as a vector for injecting scripts or breaking HTML.""" customlink = CustomLink( content_type=ContentType.objects.get_for_model(Location), name='<script>alert("Hello World")</scr...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_view_object_with_unsafe_name(self): """Ensure that JobButton names can't be used as a vector for XSS.""" self.job_button.text = "JobButton {{ obj" self.job_button.name = '<script>alert("Yo")</script>' self.job_button.validated_save() response = self.client.get(self.l...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_view_object_with_computed_field_unsafe_template(self): """Ensure that computed field templates can't be used as an XSS vector.""" self.computedfield.template = '<script>alert("Hello world!"</script>' self.computedfield.validated_save() response = self.client.get(self.locatio...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_view_object_with_unsafe_custom_link_url(self): """Ensure that custom links can't be used as a vector for injecting scripts or breaking HTML.""" customlink = CustomLink( content_type=ContentType.objects.get_for_model(Location), name="Test", text="Hello", ...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_view_object_with_computed_field_unsafe_fallback_value(self): """Ensure that computed field fallback values can't be used as an XSS vector.""" self.computedfield.template = "FOO {{ obj." self.computedfield.fallback_value = '<script>alert("Hello world!"</script>' self.computed...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def setUp(self): super().setUp() self.computedfield = ComputedField( content_type=ContentType.objects.get_for_model(LocationType), key="test", label="Computed Field", template="FOO {{ obj.name }} BAR", fallback_value="Fallback Value", ...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_view_object_with_computed_field_fallback_value(self): """Ensure that the fallback_value is rendered if the template fails to render.""" # Make the template invalid to demonstrate the fallback value self.computedfield.template = "FOO {{ obj." self.computedfield.validated_save...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_view_object_with_unsafe_text(self): """Ensure that JobButton text can't be used as a vector for XSS.""" self.job_button.text = '<script>alert("Hello world!")</script>' self.job_button.validated_save() response = self.client.get(self.location_type.get_absolute_url(), follow=T...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_view_object_with_job_button(self): """Ensure that the job button is rendered.""" response = self.client.get(self.location_type.get_absolute_url(), follow=True) self.assertEqual(response.status_code, 200) content = extract_page_body(response.content.decode(response.charset)) ...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_view_object_with_unsafe_custom_link_text(self): """Ensure that custom links can't be used as a vector for injecting scripts or breaking HTML.""" customlink = CustomLink( content_type=ContentType.objects.get_for_model(Location), name="Test", text='<script>...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def post(self, request, pk): post_data = request.POST job_button = JobButton.objects.get(pk=pk) job_model = job_button.job result = JobResult.enqueue_job( job_model=job_model, user=request.user, object_pk=post_data["object_pk"], object_...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def tests(context, lint_only=False, keepdb=False): """Run all linters and unit tests.""" black(context) flake8(context) prettier(context) eslint(context) hadolint(context) markdownlint(context) yamllint(context) ruff(context) pylint(context) check_migrations(context) chec...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def ruff(context, output_format="text"): """Run ruff to perform static analysis and linting.""" command = f"ruff --output-format {output_format} development/ examples/ nautobot/ tasks.py" run_command(context, command)
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_get_file_anonymous(self): self.client.logout() for url in self.urls: with self.subTest(url): response = self.client.get(url) self.assertHttpStatus(response, 403)
1
Python
CWE-306
Missing Authentication for Critical Function
The product does not perform any authentication for functionality that requires a provable user identity or consumes a significant amount of resources.
https://cwe.mitre.org/data/definitions/306.html
safe
def test_get_file_without_permission(self): for url in self.urls: with self.subTest(url): response = self.client.get(url) self.assertHttpStatus(response, 403)
1
Python
CWE-306
Missing Authentication for Critical Function
The product does not perform any authentication for functionality that requires a provable user identity or consumes a significant amount of resources.
https://cwe.mitre.org/data/definitions/306.html
safe
def setUp(self): super().setUp() self.test_file_1 = SimpleUploadedFile(name="test_file_1.txt", content=b"I am content.\n") self.file_proxy_1 = FileProxy.objects.create(name=self.test_file_1.name, file=self.test_file_1) self.test_file_2 = SimpleUploadedFile(name="test_file_2.txt", con...
1
Python
CWE-306
Missing Authentication for Critical Function
The product does not perform any authentication for functionality that requires a provable user identity or consumes a significant amount of resources.
https://cwe.mitre.org/data/definitions/306.html
safe
def test_get_object_with_permission(self): self.add_permissions(get_permission_for_model(FileProxy, "view")) for url in self.urls: with self.subTest(url): response = self.client.get(url) self.assertHttpStatus(response, 200)
1
Python
CWE-306
Missing Authentication for Critical Function
The product does not perform any authentication for functionality that requires a provable user identity or consumes a significant amount of resources.
https://cwe.mitre.org/data/definitions/306.html
safe
def test_get_object_with_constrained_permission(self): obj_perm = ObjectPermission( name="Test permission", constraints={"pk": self.file_proxy_1.pk}, actions=["view"], ) obj_perm.save() obj_perm.users.add(self.user) obj_perm.object_types.ad...
1
Python
CWE-306
Missing Authentication for Critical Function
The product does not perform any authentication for functionality that requires a provable user identity or consumes a significant amount of resources.
https://cwe.mitre.org/data/definitions/306.html
safe
def get_file_with_authorization(request, *args, **kwargs): """Patch db_file_storage view with authentication.""" # Make sure user has permissions queryset = FileProxy.objects.restrict(request.user, "view") get_object_or_404(queryset, file=request.GET.get("name")) return get_file(request, *args, **k...
1
Python
CWE-306
Missing Authentication for Critical Function
The product does not perform any authentication for functionality that requires a provable user identity or consumes a significant amount of resources.
https://cwe.mitre.org/data/definitions/306.html
safe
def default_helptext(self): # TODO: Port Markdown cheat sheet to internal documentation return format_html( '<i class="mdi mdi-information-outline"></i> ' '<a href="https://www.markdownguide.org/cheat-sheet/#basic-syntax" rel="noopener noreferrer">Markdown</a> ' '...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def render_markdown(value): """ Render text as Markdown Example: {{ text | render_markdown }} """ # Render Markdown html = markdown(value, extensions=["fenced_code", "tables"]) # Sanitize rendered HTML html = nautobot_logging.clean_html(html) return mark_safe(html) # noqa...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_render_markdown_security(self): self.assertEqual(helpers.render_markdown('<script>alert("XSS")</script>'), "") self.assertHTMLEqual( helpers.render_markdown('[link](javascript:alert("XSS"))'), '<p><a title="XSS" rel="noopener noreferrer">link</a>)</p>', # the traili...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_support_message(self): """Test the `support_message` tag with config and settings.""" with override_settings(): del settings.SUPPORT_MESSAGE with override_config(): self.assertHTMLEqual( helpers.support_message(), ...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_render_markdown(self): self.assertTrue(callable(helpers.render_markdown)) # Test common markdown formatting. self.assertEqual(helpers.render_markdown("**bold**"), "<p><strong>bold</strong></p>") self.assertEqual(helpers.render_markdown("__bold__"), "<p><strong>bold</strong><...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_500_custom_support_message(self, mock_get): """Nautobot's custom 500 page should be used and should include a custom support message if defined.""" url = reverse("home") with self.assertTemplateUsed("500.html"): self.client.raise_request_exception = False res...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_404_default_support_message(self): """Nautobot's custom 404 page should be used and should include a default support message.""" with self.assertTemplateUsed("404.html"): response = self.client.get("/foo/bar") self.assertContains(response, "Network to Code", status_code=...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def test_500_default_support_message(self, mock_get): """Nautobot's custom 500 page should be used and should include a default support message.""" url = reverse("home") with self.assertTemplateUsed("500.html"): self.client.raise_request_exception = False response = s...
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def clean_html(html): """Use nh3/ammonia to strip out all HTML tags and attributes except those explicitly permitted.""" return nh3.clean( html, tags=constants.HTML_ALLOWED_TAGS, attributes=constants.HTML_ALLOWED_ATTRIBUTES, url_schemes=set(settings.ALLOWED_URL_SCHEMES), )
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def default_helptext(self): return "Also used as the help text when editing models using this custom field.<br>" + super().default_helptext
1
Python
CWE-79
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
https://cwe.mitre.org/data/definitions/79.html
safe
def testConv3DTransposeZeroShapeDoNotRaiseError(self): with self.cached_session(): x_value = np.zeros([10, 0, 2, 3, 3]) f_value = np.ones((3, 3, 3, 3, 3)) y_shape = np.stack([10, 0, 2, 3, 3]) output = nn_ops.conv3d_transpose( x_value, f_value, y_shape, ...
1
Python
NVD-CWE-noinfo
null
null
null
safe
def testConv3DTransposeShapeMismatch(self): # Test case for GitHub issue 18460 x_shape = [2, 2, 3, 4, 3] f_shape = [3, 3, 3, 2, 2] y_shape = [2, 2, 6, 8, 6] strides = [1, 1, 2, 2, 2] np.random.seed(1) x_value = np.random.random_sample(x_shape).astype(np.float64) f_value = np.random.ran...
1
Python
NVD-CWE-noinfo
null
null
null
safe
def test_quantize_and_dequantize_v2(): gen_array_ops.quantize_and_dequantize_v2( input=[2.5], input_min=[1.0], input_max=[10.0], signed_input=True, num_bits=1, range_given=True, round_mode="HALF_TO_EVEN", narrow_range=True, ...
1
Python
CWE-122
Heap-based Buffer Overflow
A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().
https://cwe.mitre.org/data/definitions/122.html
safe
def test_quantize_and_dequantize_v2(): gen_array_ops.quantize_and_dequantize_v2( input=[2.5], input_min=[1.0], input_max=[10.0], signed_input=True, num_bits=1, range_given=True, round_mode="HALF_TO_EVEN", narrow_range=True, ...
1
Python
CWE-125
Out-of-bounds Read
The product reads data past the end, or before the beginning, of the intended buffer.
https://cwe.mitre.org/data/definitions/125.html
safe
def testInvalidAxis(self): @def_function.function def test_quantize_and_dequantize_v2(): gen_array_ops.quantize_and_dequantize_v2( input=[2.5], input_min=[1.0], input_max=[10.0], signed_input=True, num_bits=1, range_given=True, round...
1
Python
CWE-122
Heap-based Buffer Overflow
A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().
https://cwe.mitre.org/data/definitions/122.html
safe
def testInvalidAxis(self): @def_function.function def test_quantize_and_dequantize_v2(): gen_array_ops.quantize_and_dequantize_v2( input=[2.5], input_min=[1.0], input_max=[10.0], signed_input=True, num_bits=1, range_given=True, round...
1
Python
CWE-125
Out-of-bounds Read
The product reads data past the end, or before the beginning, of the intended buffer.
https://cwe.mitre.org/data/definitions/125.html
safe
def test_quantize_and_dequantize_v4_grad(): gen_array_ops.quantize_and_dequantize_v4_grad( gradients=[2.5], input=[2.5], input_min=[1.0], input_max=[10.0], axis=0x7fffffff)
1
Python
CWE-122
Heap-based Buffer Overflow
A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().
https://cwe.mitre.org/data/definitions/122.html
safe
def test_quantize_and_dequantize_v4_grad(): gen_array_ops.quantize_and_dequantize_v4_grad( gradients=[2.5], input=[2.5], input_min=[1.0], input_max=[10.0], axis=0x7fffffff)
1
Python
CWE-125
Out-of-bounds Read
The product reads data past the end, or before the beginning, of the intended buffer.
https://cwe.mitre.org/data/definitions/125.html
safe
def test_quantize_and_dequantize_v3(): gen_array_ops.quantize_and_dequantize_v3( input=[2.5], input_min=[1.0], input_max=[10.0], num_bits=1, signed_input=True, range_given=True, narrow_range=True, axis=0x7fffffff)
1
Python
CWE-122
Heap-based Buffer Overflow
A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().
https://cwe.mitre.org/data/definitions/122.html
safe
def test_quantize_and_dequantize_v3(): gen_array_ops.quantize_and_dequantize_v3( input=[2.5], input_min=[1.0], input_max=[10.0], num_bits=1, signed_input=True, range_given=True, narrow_range=True, axis=0x7fffffff)
1
Python
CWE-125
Out-of-bounds Read
The product reads data past the end, or before the beginning, of the intended buffer.
https://cwe.mitre.org/data/definitions/125.html
safe
def test_quantize_and_dequantize_v4(): gen_array_ops.quantize_and_dequantize_v4( input=[2.5], input_min=[1.0], input_max=[10.0], signed_input=True, num_bits=1, range_given=True, round_mode="HALF_TO_EVEN", narrow_range=True, ...
1
Python
CWE-122
Heap-based Buffer Overflow
A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().
https://cwe.mitre.org/data/definitions/122.html
safe
def test_quantize_and_dequantize_v4(): gen_array_ops.quantize_and_dequantize_v4( input=[2.5], input_min=[1.0], input_max=[10.0], signed_input=True, num_bits=1, range_given=True, round_mode="HALF_TO_EVEN", narrow_range=True, ...
1
Python
CWE-125
Out-of-bounds Read
The product reads data past the end, or before the beginning, of the intended buffer.
https://cwe.mitre.org/data/definitions/125.html
safe
def testAvgPoolGradInvalidStrideRaiseErrorProperly(self): with self.assertRaises(errors_impl.InvalidArgumentError): with self.cached_session(): orig_input_shape = [11, 9, 78, 9] grad = constant_op.constant( 0.1, shape=[16, 16, 16, 16], dtype=dtypes.float64) t = gen_nn_ops...
1
Python
CWE-120
Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow.
https://cwe.mitre.org/data/definitions/120.html
safe
def testAvgPoolGradInvalidStrideRaiseErrorProperly(self): with self.assertRaises(errors_impl.InvalidArgumentError): with self.cached_session(): orig_input_shape = [11, 9, 78, 9] grad = constant_op.constant( 0.1, shape=[16, 16, 16, 16], dtype=dtypes.float64) t = gen_nn_ops...
1
Python
CWE-122
Heap-based Buffer Overflow
A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().
https://cwe.mitre.org/data/definitions/122.html
safe
def testPoolingRatioIllegalSmallValue(self): with self.cached_session() as _: # Whether turn on `TF2_BEHAVIOR` generates different error messages with self.assertRaisesRegex( (errors.InvalidArgumentError, ValueError), r"(pooling_ratio cannot be smaller than 1, got: .*)|(is negative...
1
Python
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
def testPoolingIllegalRatioForBatch(self): with self.cached_session() as _: with self.assertRaises(errors.UnimplementedError): result = nn_ops.gen_nn_ops.fractional_avg_pool( np.zeros([3, 30, 50, 3]), [2, 3, 1.5, 1], True, True) self.evaluate(r...
1
Python
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
def testPoolingRatioIllegalSmallValue(self): with self.cached_session() as _: # Whether turn on `TF2_BEHAVIOR` generates different error messages with self.assertRaisesRegex( (errors.InvalidArgumentError, ValueError), r"(pooling_ratio cannot be smaller than 1, got: .*)|(is negative...
1
Python
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
def testPoolingIllegalRatioForBatch(self): with self.cached_session() as _: with self.assertRaises(errors.UnimplementedError): result = nn_ops.fractional_max_pool( np.zeros([3, 30, 50, 3]), [2, 3, 1.5, 1], True, True) self.evaluate(result)
1
Python
CWE-415
Double Free
The product calls free() twice on the same memory address, potentially leading to modification of unexpected memory locations.
https://cwe.mitre.org/data/definitions/415.html
safe
def testInvalidSparseInputs(self): with test_util.force_cpu(): with self.assertRaisesRegex( (ValueError, errors.InvalidArgumentError), ".*Index rank .* and shape rank .* do not match.*", ): self.evaluate( gen_sparse_ops.sparse_sparse_maximum( [[1...
1
Python
CWE-476
NULL Pointer Dereference
A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit.
https://cwe.mitre.org/data/definitions/476.html
safe
def testTensorArrayConcatFailsWhenMissingStepContainer(self): @def_function.function def func(): y = data_flow_ops.TensorArrayConcatV2( handle=["a", "b"], flow_in=0.1, dtype=dtypes.int32, element_shape_except0=1, ) return y with self.assertRaisesR...
1
Python
CWE-476
NULL Pointer Dereference
A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit.
https://cwe.mitre.org/data/definitions/476.html
safe
def func(): y = data_flow_ops.TensorArrayConcatV2( handle=["a", "b"], flow_in=0.1, dtype=dtypes.int32, element_shape_except0=1, ) return y
1
Python
CWE-476
NULL Pointer Dereference
A NULL pointer dereference occurs when the application dereferences a pointer that it expects to be valid, but is NULL, typically causing a crash or exit.
https://cwe.mitre.org/data/definitions/476.html
safe