Skip to content

Commit cf4a23d

Browse files
author
Sven Fehler
authored
Merge pull request #73 from Sv443/wip/2.1.3
2 parents 31ccb6d + 8add22e commit cf4a23d

File tree

11 files changed

+116
-91
lines changed

11 files changed

+116
-91
lines changed

changelog.txt

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,52 @@
11
====================
22

33
JokeAPI Changelog
4-
- Version 2.1.2 -
4+
- Version 2.1.3 -
55

66
====================
77

88

99

10-
Planned for the next version (2.2.0):
10+
[PLANNED: 2.2.0]
1111
- Allow definition of max requests per minute per each client (see GitHub issue #37)
1212

1313

14-
[CURRENT: 2.1.2] - Plain Text update
14+
[CURRENT: 2.1.3] - 2020 Q2 general patch #1
15+
- Added option to disable all console output but error messages (GitHub isse #72)
16+
- The content of jokes in the joke submission form is now correctly escaped and can no longer mess up the page (GitHub issue #68)
17+
- Fixed crash when parsing a malformatted URI (GitHub issue #69 (nice))
18+
- Re-flagged some jokes
19+
- Updated dependencies
20+
21+
22+
[2.1.2] - Plain Text update
1523
- Added file format "txt" to receive data as plain text
1624
- Fixed the joke submission URL in the /info endpoint data
1725
- Added HTTP error codes:
1826
- 413 Payload Too Large
1927
- 414 URI Too Long
2028

2129

22-
[OLD: 2.1.1] - Auth update hotfix
30+
[2.1.1] - Auth update hotfix
2331
- Fixed incorrect error cause when using an out-of-range ID range parameter (see GitHub issue #54)
2432
- Added submission form (https://sv443.net/jokeapi/v2#submit)
2533

2634

27-
[OLD: 2.1.0] - The auth update
35+
[2.1.0] - The auth update
2836
- Added an authorization header to make whitelisting possible without needing to have a static IP
2937
- Added the script "npm run add-token [amount]" to add one or more tokens
3038
- Improved the documentation (see GitHub issue #52)
3139
- Fixed a few bugs in the documentation
3240

3341

34-
[OLD: 2.0.1] - A few hotfixes for the big 2.0.0 updates and some very very minor features I wanted to add
42+
[2.0.1] - A few hotfixes for the big 2.0.0 updates and some very very minor features I wanted to add
3543
- Hotfixed a few bugs from the big 2.0.0 update
3644
- Fixed joke ID caching (to not serve the same jokes multiple times)
3745
- Added three new commands that are run through CI and before contributing
3846
- Enabled automated code fixing with ESLint
3947

4048

41-
[OLD: 2.0.0] - The complete rewrite - JokeAPI was completely rewritten and should now run like 100x better and be more easy to develop and maintain
49+
[2.0.0] - The complete rewrite - JokeAPI was completely rewritten and should now run like 100x better and be more easy to develop and maintain
4250
- Massively improved the "Try it out" section in the docs
4351
- Reformatted the jokes to always contain all flags
4452
- Added support for selecting multiple categories at once (for example: "https://sv443.net/jokeapi/v2/joke/Dark,Miscellaneous/")
@@ -69,24 +77,24 @@ Planned for the next version (2.2.0):
6977
- Updated the contributor guide (contributing.md file)
7078

7179

72-
[OLD: 1.1.2]
80+
[1.1.2]
7381
- joke categories are now case insensitive
7482
- trailing slashes now don't produce an "invalid category" error anymore
7583

7684

77-
[OLD: 1.1.1]
85+
[1.1.1]
7886
- better IP getter for the rate limiting
7987
- updated dependencies
8088
- very small improvements to the console window
8189

8290

83-
[OLD: 1.1.0]
91+
[1.1.0]
8492
- switched to ReadStreams instead of just loading the entire file to RAM to massively improve request performance (more details in GitHub issue #2)
8593
- this basically means it transmits the data over time, instead of loading it all to RAM and sending it at once
8694
- added rate limiting to counter DoS attacks (yes I've been getting some of those *sigh*)
8795

8896

89-
[OLD: 1.0.0]
97+
[1.0.0]
9098
- turned the single endpoint into multiple endpoints
9199
- "categories" to get all available categories
92100
- "info" to get all information about JokeAPI
@@ -117,20 +125,20 @@ Planned for the next version (2.2.0):
117125
- added this changelog
118126

119127

120-
[OLD: 0.1.2]
128+
[0.1.2]
121129
- added "Dark" category
122130
- added joke submission form
123131
- improved interactive example
124132
- modified gitignore
125133

126134

127-
[OLD: 0.1.1]
135+
[0.1.1]
128136
- added interactive example on docs page
129137
- made icon on docs page smaller
130138
- added wrapper script
131139

132140

133-
[OLD: 0.1.0]
141+
[0.1.0]
134142
- basic functionality
135143
- 47 jokes
136-
- category filter
144+
- category filter

data/jokes.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@
640640
"religious": false,
641641
"political": false,
642642
"racist": false,
643-
"sexist": false
643+
"sexist": true
644644
},
645645
"id": 47
646646
},
@@ -2536,6 +2536,19 @@
25362536
"setup": "Why are men like lawn mowers?",
25372537
"delivery": "They are very hard to get started, they make yucky smells and half the time they don’t even work.",
25382538
"id": 184
2539+
},
2540+
{
2541+
"category": "Programming",
2542+
"type": "single",
2543+
"joke": "Knock knock.\nWho's there?\nRecursion.\nRecursion who?\nKnock knock.",
2544+
"flags": {
2545+
"nsfw": false,
2546+
"religious": false,
2547+
"political": false,
2548+
"racist": false,
2549+
"sexist": false
2550+
},
2551+
"id": 185
25392552
}
25402553
]
25412554
}

data/lists/ipBlacklist.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
[
2-
"91.235.54.111",
3-
"78.98.8.142",
4-
"86.242.118.49",
5-
"46.193.128.115",
6-
"80.215.65.120",
7-
"5.40.54.7",
8-
"89.186.3.202"
2+
93
]

docs/raw/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to
10861086
<div class="indented">
10871087
I will hereby not claim any legal responsibility or liability for <!--%#INSERT:NAME#%--> and the jokes it serves (especially those from the "Dark" category).<br>
10881088
Whether it is used maliciously or breaks something in your project or someone gets offended by a joke, I can't be held accountable.<br>
1089-
Additionally, I will only be able to provide security updates for a small selection of versions, a list of which you can find <a href="https://github.com/Sv443/JokeAPI/security/policy#supported-versions" target="_blank">here.</a><br>
1089+
Additionally, I will only be able to provide security updates for a small selection of versions, a list of which you can find <a href="<!--%#INSERT:PROJGITHUBURL#%-->/security/policy#supported-versions" target="_blank">here.</a><br>
10901090
I am doing my best to ensure security and stability but there's only so much a single developer can do.<br>
10911091
Please report any issue that may arise to <a href="<!--%#INSERT:PROJGITHUBURL#%-->/issues/new/choose" target="_blank">the GitHub issue tracker</a> and I will try my best to fix it as soon as possible.<br>
10921092
If you want to contact me, you can <a href="https://sv443.net/discord" target="_blank">join my Discord server</a> (fastest way to contact me) or send me an E-Mail at <a href="mailto:[email protected]?subject=JokeAPI">[email protected]</a>

docs/raw/index.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,18 @@ function buildSubmission()
744744
}
745745

746746
var subDisp = document.getElementById("submissionDisplay");
747-
subDisp.innerHTML = JSON.stringify(submission, null, 4);
747+
748+
var escapedSubmission = JSON.parse(JSON.stringify(submission)); // copy value without reference
749+
if(type == "single")
750+
{
751+
escapedSubmission.joke = htmlEscape(submission.joke);
752+
}
753+
else if(type == "twopart")
754+
{
755+
escapedSubmission.setup = htmlEscape(submission.setup);
756+
escapedSubmission.delivery = htmlEscape(submission.delivery);
757+
}
758+
subDisp.innerHTML = JSON.stringify(escapedSubmission, null, 4);
748759

749760
var subCodeElem = document.getElementById("submissionCodeElement");
750761

@@ -770,6 +781,19 @@ function buildSubmission()
770781
}, 5);
771782
}
772783

784+
/**
785+
* Escapes unsafe HTML
786+
* @param {String} unsafeHTML
787+
* @returns {String}
788+
*/
789+
function htmlEscape(unsafeHTML)
790+
{
791+
unsafeHTML = unsafeHTML.replace(/</g, "&lt;");
792+
unsafeHTML = unsafeHTML.replace(/>/g, "&gt;");
793+
794+
return unsafeHTML;
795+
}
796+
773797
//#MARKER privacy policy
774798
function privPolMoreInfo()
775799
{

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sv443/jokeapi",
3-
"version": "2.1.2",
3+
"version": "2.1.3",
44
"description": "A RESTful API that serves jokes from many categories while also offering a lot of filtering methods",
55
"main": "JokeAPI.js",
66
"homepage": "https://sv443.net/jokeapi/v2",
@@ -50,7 +50,7 @@
5050
"json-to-pretty-yaml": "^1.2.2",
5151
"mysql": "^2.18.1",
5252
"node-wrap": "^0.2.0",
53-
"svjsl": "^1.9.0",
53+
"svjsl": "^1.9.4",
5454
"xss": "^1.0.6",
5555
"snyk": "^1.316.1"
5656
},

settings.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const settings = {
77
debug: {
88
verboseLogging: false, // set to true to enable extra debug output
99
progressBarDisabled: true, // set to true to disable the progress bar - greatly improves readability of verbose debug output
10+
onlyLogErrors: true, // set to true to disable sending any console logs but error messages
1011
},
1112
info: {
1213
name: "JokeAPI", // the name of JokeAPI
@@ -24,6 +25,18 @@ const settings = {
2425
infoMsg: "If you want to be updated on the status and future updates of JokeAPI or need some help, please consider joining my Discord server: https://sv443.net/discord",
2526
privacyPolicyUrl: "https://sv443.net/privacypolicy/en"
2627
},
28+
wrapper: {
29+
mainFilePath: "./src/main.js", // main script file
30+
skipWrapping: true, // whether or not to skip the wrapping through node-wrap
31+
wrapperSettings: {
32+
console: true, // whether Node-Wrap should log to the console
33+
crashTimeout: 2000, // timeout (in ms) until the process should be restarted after a crash
34+
logFile: "./data/logs/wrapper.log", // Node-Wrap log file
35+
logTimestamp: true, // whether to add a timestamp to the log
36+
restartOnCrash: true, // whether to restart the process after a crash
37+
restartTimeout: 0, // timeout (in ms) until the process should be started again after a restart has been requested
38+
},
39+
},
2740
init: {
2841
initDirs: [ // directories that should be generated if they don't exist - paths relative to root of project - doesn't necessarily need trailing slash
2942
"./data/logs",
@@ -41,18 +54,6 @@ const settings = {
4154
disableLogging: false, // set to true to disable logging a character on each request
4255
blacklistLoggingEnabled: true, // whether or not to log the character when an IP is on the blacklist
4356
},
44-
wrapper: {
45-
mainFilePath: "./src/main.js", // main script file
46-
skipWrapping: false, // whether or not to skip the wrapping through node-wrap
47-
wrapperSettings: {
48-
console: true, // whether Node-Wrap should log to the console
49-
crashTimeout: 2000, // timeout (in ms) until the process should be restarted after a crash
50-
logFile: "./data/logs/wrapper.log", // Node-Wrap log file
51-
logTimestamp: true, // whether to add a timestamp to the log
52-
restartOnCrash: true, // whether to restart the process after a crash
53-
restartTimeout: 0, // timeout (in ms) until the process should be started again after a restart has been requested
54-
},
55-
},
5657
jokes: {
5758
jokesFormatVersion: 2, // current joke format version
5859
jokesFilePath: "./data/jokes.json", // path to the jokes file
@@ -182,4 +183,4 @@ const settings = {
182183
}
183184
}
184185

185-
module.exports = settings;
186+
module.exports = settings;

src/classes/FilteredJoke.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,16 @@ class FilteredJoke
156156
return false;
157157
}
158158

159-
this._searchString = decodeURIComponent(searchString);
160-
return true;
159+
try
160+
{
161+
this._searchString = decodeURIComponent(searchString);
162+
return true;
163+
}
164+
catch(err)
165+
{
166+
this._errors.push("The URI is malformatted or the \"contains\" parameter isn't correctly percent-encoded");
167+
return false;
168+
}
161169
}
162170

163171
/**

src/logRequest.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const logRequest = (type, additionalInfo, analyticsData) => {
2626
let spacerDisabled = false;
2727
let logChar = settings.logging.logChar;
2828

29+
if(settings.debug.onlyLogErrors)
30+
logDisabled = true;
31+
2932
switch(type)
3033
{
3134
case "success":
@@ -75,6 +78,9 @@ const logRequest = (type, additionalInfo, analyticsData) => {
7578
}
7679
break;
7780
case "error":
81+
if(settings.debug.onlyLogErrors)
82+
logDisabled = false;
83+
7884
color = settings.colors.ratelimit;
7985
logType = "error";
8086

@@ -93,7 +99,7 @@ const logRequest = (type, additionalInfo, analyticsData) => {
9399
break;
94100
case "docsrecompiled":
95101
color = settings.colors.docsrecompiled;
96-
logChar = `r${jsl.colors.rst} `;
102+
logChar = "r ";
97103
break;
98104
case "submission":
99105
logChar = `\n\n${jsl.colors.fg.blue}⯈ Got a submission${!jsl.isEmpty(additionalInfo) ? ` from ${jsl.colors.fg.yellow}${additionalInfo.substring(0, 8)}` : ""}${jsl.colors.rst}\n\n`;
@@ -147,11 +153,16 @@ const initMsg = (initTimestamp) => {
147153
console.log(` ├─ Analytics database ${jsl.colors.fg.red}not connected${jsl.colors.rst}`);
148154
console.log(` ├─ ${settings.info.name} is listening at ${jsl.colors.fg.green}0.0.0.0:${settings.httpServer.port}${jsl.colors.rst}`);
149155
console.log(` └─ Initialization took ${jsl.colors.fg.green}${(new Date().getTime() - initTimestamp).toFixed(0)}ms${jsl.colors.rst}`);
150-
console.log(`\n\n ${settings.colors.success}${settings.logging.logChar} Success ${settings.colors.docs}${settings.logging.logChar} Docs ${settings.colors.ratelimit}${settings.logging.logChar} RateLimited ${settings.colors.error}${settings.logging.logChar} Error${jsl.colors.rst}`);
151-
process.stdout.write("\x1b[2m");
152-
process.stdout.write("└┬───────────────────────────────────────┘\n");
153-
process.stdout.write(" └─► ");
154-
process.stdout.write("\x1b[0m");
156+
process.stdout.write("\n");
157+
158+
if(!settings.debug.onlyLogErrors)
159+
{
160+
console.log(`\n ${settings.colors.success}${settings.logging.logChar} Success ${settings.colors.docs}${settings.logging.logChar} Docs ${settings.colors.ratelimit}${settings.logging.logChar} RateLimited ${settings.colors.error}${settings.logging.logChar} Error${jsl.colors.rst}`);
161+
process.stdout.write("\x1b[2m");
162+
process.stdout.write("└┬───────────────────────────────────────┘\n");
163+
process.stdout.write(" └─► ");
164+
process.stdout.write(jsl.colors.rst);
165+
}
155166
}
156167

157168
module.exports = logRequest;

0 commit comments

Comments
 (0)