You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Typosquatting: add typosquatting check service codes (#6315)
Add the codes of typosquatting algorithms and retrieve the latest owner list info.
1. Typosquatting check service with distance calculation and comparison;
2. Normalize the string before checking;
3. Call `public bool IsDistanceLessThanThreshold(string str1, string str2, int threshold)` to compare two strings; (changed to private)
4. Call `public bool IsUploadedPackageIdTyposquatting(string uploadedPackageId)` to check typosquatting in the checlist.
Fixes: https://github.com/NuGet/Engineering/issues/1593
// Copyright (c) .NET Foundation. All rights reserved.
2
+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
+
4
+
namespaceNuGetGallery
5
+
{
6
+
/// <summary>
7
+
/// This interface is used to check typo-squatting of uploaded package ID with the owner.
8
+
/// </summary>
9
+
publicinterfaceITyposquattingCheckService
10
+
{
11
+
/// <summary>
12
+
/// The function is used to check whether the uploaded package is a typo-squatting package.
13
+
/// </summary>
14
+
/// <param name="uploadedPackageId"> The package ID of the uploaded package. We check the pacakge ID with the packages in the gallery for typo-squatting issue</param>
15
+
/// <param name="uploadedPackageOwner"> The package owner of the uploaded package.</param>
// Copyright (c) .NET Foundation. All rights reserved.
2
+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
+
4
+
namespaceNuGetGallery
5
+
{
6
+
/// <summary>
7
+
/// The interface and method are used to check the latest info like owners' list from the DB for typo-squatting.
8
+
/// </summary>
9
+
publicinterfaceITyposquattingUserService
10
+
{
11
+
/// <summary>
12
+
/// The function is used to check the latest info of owners from the DB to confirm that the uploaded package and the conflict package are not shared by the same user.
13
+
/// </summary>
14
+
/// <param name="packageId"> The package ID of the potential conflict package in the gallery.
15
+
/// We'd like to double check that the conflict package and uploaded package don't share the same user</param>
16
+
/// <param name="userName"> The package owner of the uploaded package.</param>
/// The following function is used to traceback based on the construction path and align two strings.
125
+
/// Example: For two strings: "asp.net" "aspnet". After traceback and alignment, we will have aligned strings as "asp.net" "asp*net" ('*' is the placeholder).
126
+
/// The returned strings contain the two inputted strings after alignment.
thrownewArgumentException("Invalidate operation for edit distance trace back: "+path[i,j]);
158
+
}
159
+
}
160
+
161
+
for(vark=0;k<i;k++)
162
+
{
163
+
newStr2.Insert(k,PlaceholderForAlignment);
164
+
}
165
+
166
+
for(vark=0;k<j;k++)
167
+
{
168
+
newStr1.Insert(k,PlaceholderForAlignment);
169
+
}
170
+
171
+
alignedStrs[0]=newStr1.ToString();
172
+
alignedStrs[1]=newStr2.ToString();
173
+
174
+
returnalignedStrs;
175
+
}
176
+
177
+
/// <summary>
178
+
/// The following function is used to refresh the edit distance based on predefined rules. (Insert/Delete special characters will not account for distance)
179
+
/// Example: For two aligned strings: "asp.net" "asp*net" ('*' is the placeholder), we will scan the two strings again and the mapping from '.' to '*' will not account for the distance.
180
+
/// So the final distance will be 0 for these two strings "asp.net" "aspnet".
0 commit comments