-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue #62 #63
Fix issue #62 #63
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,42 +40,22 @@ | |
def index(): | ||
if request.method == 'POST': | ||
planet = request.form.get('planet') | ||
sanitized_planet = re.sub(r'[<>(){}[\]]', '', planet) | ||
|
||
if 'script' in sanitized_planet.lower() : | ||
return '<h2>Blocked</h2></p>' | ||
|
||
elif sanitized_planet: | ||
details = get_planet_info(sanitized_planet) | ||
|
||
if planet: | ||
return f'<h2>Planet Details:</h2><p>{get_planet_info(planet)}</p>' | ||
else: | ||
return '<h2>Please enter a planet name.</h2>' | ||
|
||
return render_template('index.html') | ||
|
||
@app.route('/getPlanetInfo', methods=['GET']) | ||
def get_planet_info_endpoint(): | ||
planet = request.args.get('planet') | ||
sanitized_planet = re.sub(r'[<>(){}[\]]', '', planet) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @evarga The idea behind this level and especially this specific line of code was to show that many devs might reinvent the wheel and try to blocklist some symbols to avoid injection attacks. Therefore, I feel that the despite the code could be simplified more of course, the goal was to trick students to think that is not vulnerable due to the checks implemented. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The This is why I have recommended to skip sanitization in the current form; otherwise, students would need to apply a dozen of advanced tricks to figure out how to inject improper payload despite the above sanitization. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need students to face some difficulty in order to learn more in this level and I see your point about the solution assumption, so if possible, feel free to propose something on the solution file and keep the rest of structure (and regex in code file) as it is, or with minimal changes to keep the essence of the game. The learning objective was to show students an example of reinventing the wheel through block-listing symbols instead of using a library etc. It's a good idea to show them that when a developer creates a manual control, it's under the assumption that inputs will be X, Y, Z, while in reality, skilled attackers can do W, Q, etc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that an additional level of complexity will definitely improve the learning experience. I will insert back the checks into the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you!!! |
||
|
||
if 'script' in sanitized_planet.lower() : | ||
return '<h2>Blocked</h2></p>' | ||
|
||
elif sanitized_planet: | ||
details = get_planet_info(sanitized_planet) | ||
|
||
if planet: | ||
return f'<h2>Planet Details:</h2><p>{get_planet_info(planet)}</p>' | ||
sanitized_planet = re.sub(r'[<>{}[\]]', '', planet if planet else '') | ||
|
||
if sanitized_planet: | ||
if 'script' in sanitized_planet.lower() : | ||
return '<h2>Blocked</h2></p>' | ||
|
||
return render_template('details.html', | ||
planet=sanitized_planet, | ||
info=get_planet_info(sanitized_planet)) | ||
else: | ||
return '<h2>Please enter a planet name.</h2>' | ||
|
||
return render_template('index.html') | ||
|
||
def get_planet_info(planet): | ||
if planet in planet_data: | ||
return planet_data[planet] | ||
else: | ||
return f'No information found for {planet}.' | ||
return planet_data.get(planet, 'Unknown planet.') | ||
|
||
if __name__ == '__main__': | ||
app.run() |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Here are two steps to simulate an attack: | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whenever we can have an automated test instead of a manual one, let's do it, and here was an example of having automated ones There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, the original
Honestly, I don't see anything failing here nor an XSS attack in action. For the latter to happen, rendering must be performed over the response to actually execute any embedded active content. Again, the fact that those P.S. It is also a very bad practice to return form an API endpoint a stylized HTML content. This is another reason why I've decided to completely omit it from the revised version, as it would even more confuse students where to look for issues. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense now, thanks for pointing out. See my comment above and if you can re-write your proposal following what I suggested then it's a win-win. In addition, feel free to either try to automate the hack file or keep it manual, making sure of course that reflects the changes on the code file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I will alter the code accordingly for attaining a desirable win-win state. |
||
1. Start the applicsation as instructed in 'code.py' | ||
2. Enter in the input field for planet the following content: <img src='x' onerror='alert(1)'> | ||
|
||
Your application must present a message that such a planet is unknown to the system without | ||
showing an alert box. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
How does the site handle user input before displaying it? | ||
How does the site handle user input before and after displaying it? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Planet Details</title> | ||
<style> | ||
body { | ||
font-family: Arial, Helvetica, sans-serif; | ||
background-color: #121212; | ||
color: #ffffff; | ||
} | ||
|
||
h2 { | ||
text-align: center; | ||
margin-top: 30px; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<h2>Planet Details</h2> | ||
<p>Planet name: <span id="name">{{ planet | safe }}</span></p> | ||
<p>Planet info: {{ info | safe }}</p> | ||
<br/> | ||
<p>Search in Google for more information about the planet: <span id="planet"/></p> | ||
<script> | ||
document.getElementById("planet").innerHTML = document.getElementById("name").textContent; | ||
</script> | ||
</body> | ||
|
||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal I mentioned in the comment below, it's also achieved (hopefully!) with the chosen variable names, like
sanitized_planet
for example, making someone think that it's sanitized, hence safe!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment above.