mirror of
https://github.com/searxng/searxng.git
synced 2026-06-06 18:07:18 +02:00
cbf97fd262f26b3d6e215bfb22dd9bb00981be23
The implementation is basically a 1:1 port of the reverse engineered
swisscows JavaScript code. (it's been obfuscated, so I've restructured it
and made the variable names idiomatic instead of obfuscated var names like "a", "o", "i")
```js
/*
e: "/v5/images/search"
t: {
itemsCount: "50"
locale: "de-DE"
offset: "50"
query: "test"
spellcheck: "true"
}
*/
// HASH library used: https://github.com/h2non/jshashes
function generateNonceAndSignature(queryParams, urlPath) {
// urlPath = "/v5/images/search"
// sort keys alphabetically and join to query string
let queryStringSorted = '?' + U().stringify(queryParams, {
arrayFormat: 'repeat',
allowDots: !0
}).split('&').map(e => {
let[key, value] = e.split('=');
return [key, decodeURIComponent(value)]
}).sort((e, t) => e[0].localeCompare(t[0])).map(e => e.join('=')).join('&');
function caesarShift(str, offset = 13) {
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
let result = [];
for (let a = 0; a < str.length; a++) {
let c = str[a],
alphabetIndex = alphabet.indexOf(c.toLowerCase());
if ( - 1 !== alphabetIndex) {
alphabetIndex += offset;
while (alphabetIndex >= alphabet.length) alphabetIndex -= alphabet.length;
c = c === c.toUpperCase() ? alphabet[alphabetIndex] : alphabet[alphabetIndex].toUpperCase()
}
result.push(c)
}
return result.join('')
}
const r = new (sha256Instance()).SHA256;
const random = randomString(32);
const randomShifted = caesarShift(random);
let to_hash = [urlPath, queryStringSorted, randomShifted].join('');
let signature = r.b64(to_hash);
signature = signature.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
return {
nonce: random,
signature: signature
}
}
function randomString(length) {
let t = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~',
n = '';
for (let r = 0; r < length; r++) n += t.charAt(Math.floor(Math.random() * t.length));
return n
}
```
.. SPDX-License-Identifier: AGPL-3.0-or-later .. _metasearch engine: https://en.wikipedia.org/wiki/Metasearch_engine .. _Installation guide: https://docs.searxng.org/admin/installation.html .. _Configuration guide: https://docs.searxng.org/admin/settings/index.html .. _CONTRIBUTING: https://github.com/searxng/searxng/blob/master/CONTRIBUTING.rst .. _LICENSE: https://github.com/searxng/searxng/blob/master/LICENSE .. figure:: https://raw.githubusercontent.com/searxng/searxng/master/client/simple/src/brand/searxng.svg :target: https://searxng.org :alt: SearXNG :width: 512px SearXNG is a `metasearch engine`_. Users are neither tracked nor profiled. .. image:: https://img.shields.io/badge/organization-3050ff?style=flat-square&logo=searxng&logoColor=fff&cacheSeconds=86400 :target: https://github.com/searxng :alt: Organization .. image:: https://img.shields.io/badge/documentation-3050ff?style=flat-square&logo=readthedocs&logoColor=fff&cacheSeconds=86400 :target: https://docs.searxng.org :alt: Documentation .. image:: https://img.shields.io/github/license/searxng/searxng?style=flat-square&label=license&color=3050ff&cacheSeconds=86400 :target: https://github.com/searxng/searxng/blob/master/LICENSE :alt: License .. image:: https://img.shields.io/github/commit-activity/y/searxng/searxng/master?style=flat-square&label=commits&color=3050ff&cacheSeconds=3600 :target: https://github.com/searxng/searxng/commits/master/ :alt: Commits .. image:: https://img.shields.io/weblate/progress/searxng?server=https%3A%2F%2Ftranslate.codeberg.org&style=flat-square&label=translated&color=3050ff&cacheSeconds=86400 :target: https://translate.codeberg.org/projects/searxng/ :alt: Translated Setup ===== To install SearXNG, see `Installation guide`_. To fine-tune SearXNG, see `Configuration guide`_. Further information on *how-to* can be found `here <https://docs.searxng.org/admin/index.html>`_. Connect ======= If you have questions or want to connect with others in the community: - `#searxng:matrix.org <https://matrix.to/#/#searxng:matrix.org>`_ Contributing ============ See CONTRIBUTING_ for more details. License ======= This project is licensed under the GNU Affero General Public License (AGPL-3.0). See LICENSE_ for more details.
Languages
Python
81%
Shell
6.4%
HTML
5.3%
Less
4%
TypeScript
2.9%
Other
0.3%