Parcourir la source

Merge pull request #1941 from Jose-Tejera/agent/reject-nonhex-client-paste-ids

Reject non-hexadecimal paste IDs in the client
El RIDO il y a 1 semaine
Parent
commit
e747698c88
2 fichiers modifiés avec 9 ajouts et 2 suppressions
  1. 1 1
      js/privatebin.js
  2. 8 1
      js/test/Model.js

+ 1 - 1
js/privatebin.js

@@ -1450,7 +1450,7 @@ window.PrivateBin = (function () {
          * @throws {string}
          */
         me.getPasteId = function () {
-            const idRegEx = /^[a-z0-9]{16}$/;
+            const idRegEx = /^[a-f0-9]{16}$/;
 
             // return cached value
             if (id !== null) {

+ 8 - 1
js/test/Model.js

@@ -122,6 +122,14 @@ describe('Model', function () {
                 }
             ));
         });
+        it('throws exception on non-hexadecimal document IDs', () => {
+            const clean = globalThis.cleanup('', {
+                url: 'https://example.com/?gggggggggggggggg#key'
+            });
+            assert.throws(() => PrivateBin.Model.getPasteId());
+            PrivateBin.Model.reset();
+            clean();
+        });
     });
 
     describe('getPasteKey', function () {
@@ -254,4 +262,3 @@ describe('Model', function () {
         });
     });
 });
-